diff --git a/src/core/generation.hpp b/src/core/generation.hpp index 4b9ef1a..56dc929 100644 --- a/src/core/generation.hpp +++ b/src/core/generation.hpp @@ -12,6 +12,8 @@ #include "shell.hpp" #include "singleton.hpp" +class RootWrapper; + class EngineGeneration: public QObject { Q_OBJECT; @@ -28,6 +30,7 @@ public: static EngineGeneration* findObjectGeneration(QObject* object); + RootWrapper* wrapper = nullptr; QmlScanner scanner; QsUrlInterceptor urlInterceptor; QsInterceptNetworkAccessManagerFactory interceptNetFactory; diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index b6d50fa..2beee36 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -17,6 +17,7 @@ #include #include +#include "generation.hpp" #include "qmlscreen.hpp" #include "rootwrapper.hpp" @@ -144,8 +145,8 @@ QQmlListProperty QuickshellGlobal::screens() { } void QuickshellGlobal::reload(bool hard) { - auto* rootobj = QQmlEngine::contextForObject(this)->engine()->parent(); - auto* root = qobject_cast(rootobj); + auto* generation = EngineGeneration::findObjectGeneration(this); + auto* root = generation == nullptr ? nullptr : generation->wrapper; if (root == nullptr) { qWarning() << "cannot find RootWrapper for reload, ignoring request"; diff --git a/src/core/rootwrapper.cpp b/src/core/rootwrapper.cpp index fbb624e..e318028 100644 --- a/src/core/rootwrapper.cpp +++ b/src/core/rootwrapper.cpp @@ -46,6 +46,7 @@ void RootWrapper::reloadGraph(bool hard) { scanner.scanQmlFile(this->rootPath); auto* generation = new EngineGeneration(std::move(scanner)); + generation->wrapper = this; // todo: move into EngineGeneration if (this->generation != nullptr) {