From 3b769f82d67d30a90ced94138d039aa448e5dc47 Mon Sep 17 00:00:00 2001 From: Anmol Gautam Date: Tue, 12 Jun 2018 13:52:16 +0530 Subject: [PATCH] delete engine on qml-pluign unload --- src/lib/plugins/qml/qmlplugininterface.cpp | 1 + src/lib/plugins/qml/qmlplugininterface.h | 3 +++ src/lib/plugins/qml/qmlpluginloader.cpp | 9 ++++++++- src/lib/plugins/qml/qmlpluginloader.h | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) 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;