diff --git a/src/lib/plugins/qml/qmlplugininterface.cpp b/src/lib/plugins/qml/qmlplugininterface.cpp index 149d8e2c3..ec28b1f3e 100644 --- a/src/lib/plugins/qml/qmlplugininterface.cpp +++ b/src/lib/plugins/qml/qmlplugininterface.cpp @@ -48,6 +48,7 @@ void QmlPluginInterface::unload() } m_jsUnload.call(); + emit qmlPluginUnloaded(); } bool QmlPluginInterface::testPlugin() diff --git a/src/lib/plugins/qml/qmlplugininterface.h b/src/lib/plugins/qml/qmlplugininterface.h index 2b6d9cd99..22641ac5f 100644 --- a/src/lib/plugins/qml/qmlplugininterface.h +++ b/src/lib/plugins/qml/qmlplugininterface.h @@ -40,6 +40,9 @@ public: bool testPlugin(); void setName(const QString &name); +Q_SIGNALS: + void qmlPluginUnloaded(); + private: QString m_name; QJSValue m_jsInit; diff --git a/src/lib/plugins/qml/qmlpluginloader.cpp b/src/lib/plugins/qml/qmlpluginloader.cpp index 5ae1cf1eb..f7c3b2e74 100644 --- a/src/lib/plugins/qml/qmlpluginloader.cpp +++ b/src/lib/plugins/qml/qmlpluginloader.cpp @@ -19,13 +19,20 @@ QmlPluginLoader::QmlPluginLoader(const QString &path) { + m_path = path; m_engine = new QQmlEngine(); - m_component = new QQmlComponent(m_engine, path); + m_component = new QQmlComponent(m_engine, m_path); } void QmlPluginLoader::createComponent() { m_interface = qobject_cast(m_component->create()); + connect(m_interface, &QmlPluginInterface::qmlPluginUnloaded, this, [this]{ + delete m_component; + delete m_engine; + m_engine = new QQmlEngine(); + m_component = new QQmlComponent(m_engine, m_path); + }); } QQmlComponent *QmlPluginLoader::component() const diff --git a/src/lib/plugins/qml/qmlpluginloader.h b/src/lib/plugins/qml/qmlpluginloader.h index 541c1f14a..8385d031e 100644 --- a/src/lib/plugins/qml/qmlpluginloader.h +++ b/src/lib/plugins/qml/qmlpluginloader.h @@ -22,8 +22,9 @@ #include "qmlplugininterface.h" -class QmlPluginLoader +class QmlPluginLoader : public QObject { + Q_OBJECT public: explicit QmlPluginLoader(const QString &path); void createComponent(); @@ -31,6 +32,7 @@ public: QmlPluginInterface *instance() const; void setName(const QString &name); private: + QString m_path; QQmlEngine *m_engine; QQmlComponent *m_component; QmlPluginInterface *m_interface;