summaryrefslogtreecommitdiff
path: root/src/ivicore
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2020-01-17 16:30:28 +0100
committerDominik Holland <dominik.holland@qt.io>2020-01-17 19:34:17 +0100
commit9fd63dd467506c35a541fa09dd63d16fb7ebf9bd (patch)
treea63efe13da338614afaa654a4180962bb89a228b /src/ivicore
parent5521135b4587e4126d3d0257b04370bd02741d20 (diff)
downloadqtivi-9fd63dd467506c35a541fa09dd63d16fb7ebf9bd.tar.gz
Delay the QIviPendingReply type registration
When QtIviCore is loaded at runtime the init function is executed right away before all types are initialized. This causes a crash on windows and we now delay the initialization until the library is ready. Change-Id: I979f48c811f6a7f10facb59ef381239d5ea80367 Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'src/ivicore')
-rw-r--r--src/ivicore/qivipendingreply.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/ivicore/qivipendingreply.cpp b/src/ivicore/qivipendingreply.cpp
index 2caa926..0229d39 100644
--- a/src/ivicore/qivipendingreply.cpp
+++ b/src/ivicore/qivipendingreply.cpp
@@ -73,13 +73,23 @@ void qiviRegisterPendingReplyBasicTypes() {
if (once)
return;
- qRegisterMetaType<QIviPendingReplyBase>("QIviPendingReplyBase");
- QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QTIVI_ADD_STATIC_METATYPE)
- QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QTIVI_ADD_STATIC_METATYPE)
- QT_FOR_EACH_STATIC_CORE_POINTER(QTIVI_ADD_STATIC_METATYPE)
- QT_FOR_EACH_STATIC_CORE_TEMPLATE(QTIVI_ADD_STATIC_METATYPE)
- QT_FOR_EACH_STATIC_CORE_CLASS(QTIVI_ADD_STATIC_METATYPE)
- QT_FOR_EACH_STATIC_ALIAS_TYPE(QTIVI_ADD_STATIC_METATYPE2)
+ // This function is registered as Q_COREAPP_STARTUP_FUNCTION, which makes sure
+ // it is run after the QCoreApplication constructor to ensure we can register
+ // types.
+ // In case the library is loaded at runtime (because of a qml plugin dependency),
+ // the init function would be registered and executed right away before the
+ // rest of the library is initialized (e.g. the QMetaObject of QIviPendingReplyBase).
+ // The singleshot timer makes sure the registration is done in the next event
+ // loop run, when everything is ready.
+ QTimer::singleShot(0, []() {
+ qRegisterMetaType<QIviPendingReplyBase>("QIviPendingReplyBase");
+ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QTIVI_ADD_STATIC_METATYPE)
+ QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QTIVI_ADD_STATIC_METATYPE)
+ QT_FOR_EACH_STATIC_CORE_POINTER(QTIVI_ADD_STATIC_METATYPE)
+ QT_FOR_EACH_STATIC_CORE_TEMPLATE(QTIVI_ADD_STATIC_METATYPE)
+ QT_FOR_EACH_STATIC_CORE_CLASS(QTIVI_ADD_STATIC_METATYPE)
+ QT_FOR_EACH_STATIC_ALIAS_TYPE(QTIVI_ADD_STATIC_METATYPE2)
+ });
once = true;
}