diff --git a/src/quickaddons/configmodule.cpp b/src/quickaddons/configmodule.cpp --- a/src/quickaddons/configmodule.cpp +++ b/src/quickaddons/configmodule.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -62,7 +62,7 @@ void authStatusChanged(int status); ConfigModule *_q; - KDeclarative::QmlObject *_qmlObject; + KDeclarative::QmlObjectSharedEngine *_qmlObject; ConfigModule::Buttons _buttons; const KAboutData *_about; QString _rootOnlyMessage; @@ -103,7 +103,7 @@ ConfigModule::~ConfigModule() { - ConfigModulePrivate::s_rootObjects.remove(d->_qmlObject->engine()); + ConfigModulePrivate::s_rootObjects.remove(d->_qmlObject->rootContext()); delete d->_qmlObject; delete d->_about; @@ -116,8 +116,19 @@ { //at the moment of the attached object creation, the root item is the only one that hasn't a parent //only way to avoid creation of this attached for everybody but the root item - if (!object->parent() && ConfigModulePrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) { - return ConfigModulePrivate::s_rootObjects.value(QtQml::qmlEngine(object)); + const QQmlEngine *engine = QtQml::qmlEngine(object); + QQmlContext *cont = QQmlEngine::contextForObject(object); + + //Search the qml context that is the "root" for the sharedqmlobject, which + //is an ancestor of QQmlEngine::contextForObject(object) and the direct child + //of the engine's root context: we can do this assumption on the internals as + //we are distributed on the same repo. + while (cont->parentContext() && cont->parentContext() != engine->rootContext()) { + cont = cont->parentContext(); + } + + if (!object->parent() && ConfigModulePrivate::s_rootObjects.contains(cont)) { + return ConfigModulePrivate::s_rootObjects.value(cont); } else { return nullptr; } @@ -128,8 +139,8 @@ if (d->_qmlObject) { return qobject_cast(d->_qmlObject->rootObject()); } - d->_qmlObject = new KDeclarative::QmlObject(this); - ConfigModulePrivate::s_rootObjects[d->_qmlObject->engine()] = this; + d->_qmlObject = new KDeclarative::QmlObjectSharedEngine(this); + ConfigModulePrivate::s_rootObjects[d->_qmlObject->rootContext()] = this; d->_qmlObject->setTranslationDomain(aboutData()->componentName()); d->_qmlObject->setInitializationDelayed(true);