From 7553c3e18a59accd97ea17324a869b3c2a225059 Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Sun, 17 Jun 2018 17:20:20 +0200 Subject: [PATCH] fix registry creation lock and missing init --- src/mvvmcore/serviceregistry.cpp | 15 ++++++++------- src/mvvmcore/serviceregistry_p.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) 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;