diff --git a/src/mvvmcore/serviceregistry.cpp b/src/mvvmcore/serviceregistry.cpp index fbc846a..25b87d1 100644 --- a/src/mvvmcore/serviceregistry.cpp +++ b/src/mvvmcore/serviceregistry.cpp @@ -131,6 +131,13 @@ void ServiceRegistryPrivate::injectLocked(QObject *object) tProp.write(object, variant); } } + + // if available, call qtmvvm_init + auto initMethod = metaObject->indexOfMethod("qtmvvm_init()"); + if(initMethod != -1) { + auto method = metaObject->method(initMethod); + method.invoke(object); + } } @@ -199,13 +206,7 @@ ServiceRegistryPrivate::MetaServiceInfo::MetaServiceInfo(const QMetaObject *meta QObject *ServiceRegistryPrivate::MetaServiceInfo::construct(ServiceRegistryPrivate *d) const { - auto instance = d->constructInjectedLocked(metaObject, nullptr); //services are created without a parent - auto initMethod = metaObject->indexOfMethod("qtmvvm_init()"); - if(initMethod != -1) { - auto method = metaObject->method(initMethod); - method.invoke(instance); - } - return instance; + return d->constructInjectedLocked(metaObject, nullptr); //services are created without a parent } // ------------- Exceptions Implementation ------------- diff --git a/src/mvvmcore/serviceregistry_p.h b/src/mvvmcore/serviceregistry_p.h index 390a273..79af7f8 100644 --- a/src/mvvmcore/serviceregistry_p.h +++ b/src/mvvmcore/serviceregistry_p.h @@ -52,7 +52,7 @@ public: const QMetaObject *metaObject; }; - QMutex serviceMutex; + QMutex serviceMutex{QMutex::Recursive}; QHash> services; bool serviceBlocked(const QByteArray &iid) const;