Browse Source

fix registry creation lock and missing init

pull/2/head
Skycoder42 7 years ago
parent
commit
7553c3e18a
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 15
      src/mvvmcore/serviceregistry.cpp
  2. 2
      src/mvvmcore/serviceregistry_p.h

15
src/mvvmcore/serviceregistry.cpp

@ -131,6 +131,13 @@ void ServiceRegistryPrivate::injectLocked(QObject *object)
tProp.write(object, variant); 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 QObject *ServiceRegistryPrivate::MetaServiceInfo::construct(ServiceRegistryPrivate *d) const
{ {
auto instance = d->constructInjectedLocked(metaObject, nullptr); //services are created without a parent return 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;
} }
// ------------- Exceptions Implementation ------------- // ------------- Exceptions Implementation -------------

2
src/mvvmcore/serviceregistry_p.h

@ -52,7 +52,7 @@ public:
const QMetaObject *metaObject; const QMetaObject *metaObject;
}; };
QMutex serviceMutex; QMutex serviceMutex{QMutex::Recursive};
QHash<QByteArray, QSharedPointer<ServiceInfo>> services; QHash<QByteArray, QSharedPointer<ServiceInfo>> services;
bool serviceBlocked(const QByteArray &iid) const; bool serviceBlocked(const QByteArray &iid) const;

Loading…
Cancel
Save