diff options
-rw-r--r-- | src/imports/qtquick2/plugin.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlextensionplugin.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlextensionplugin.h | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 14 |
4 files changed, 24 insertions, 4 deletions
diff --git a/src/imports/qtquick2/plugin.cpp b/src/imports/qtquick2/plugin.cpp index 4e14aff15e..dde0b7207a 100644 --- a/src/imports/qtquick2/plugin.cpp +++ b/src/imports/qtquick2/plugin.cpp @@ -64,10 +64,11 @@ public: QQmlQtQuick2Module::defineModule(); } - ~QtQuick2Plugin() override + void unregisterTypes() override { if (moduleDefined) QQmlQtQuick2Module::undefineModule(); + moduleDefined = false; } bool moduleDefined = false; diff --git a/src/qml/qml/qqmlextensionplugin.cpp b/src/qml/qml/qqmlextensionplugin.cpp index 7a62c967e7..f779199b74 100644 --- a/src/qml/qml/qqmlextensionplugin.cpp +++ b/src/qml/qml/qqmlextensionplugin.cpp @@ -117,6 +117,16 @@ QUrl QQmlExtensionPlugin::baseUrl() const } /*! + \since 6.0 + + Override this method to unregister types manually registered in registerTypes. +*/ +void QQmlExtensionPlugin::unregisterTypes() +{ + +} + +/*! \internal */ diff --git a/src/qml/qml/qqmlextensionplugin.h b/src/qml/qml/qqmlextensionplugin.h index ef7ff422cd..78371106bd 100644 --- a/src/qml/qml/qqmlextensionplugin.h +++ b/src/qml/qml/qqmlextensionplugin.h @@ -64,6 +64,7 @@ public: QUrl baseUrl() const; void registerTypes(const char *uri) override = 0; + virtual void unregisterTypes(); void initializeEngine(QQmlEngine *engine, const char *uri) override; private: diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 076a23c1dd..47f7b40938 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -161,9 +161,17 @@ void qmlClearEnginePlugins() #if QT_CONFIG(library) for (auto &plugin : qAsConst(*plugins)) { QPluginLoader* loader = plugin.loader; - if (loader && !loader->unload()) - qWarning("Unloading %s failed: %s", qPrintable(plugin.uri), qPrintable(loader->errorString())); - delete loader; + if (loader) { + auto extensionPlugin = qobject_cast<QQmlExtensionPlugin *>(loader->instance()); + if (extensionPlugin) { + extensionPlugin->unregisterTypes(); + } +#ifndef Q_OS_MACOS + if (!loader->unload()) + qWarning("Unloading %s failed: %s", qPrintable(plugin.uri), qPrintable(loader->errorString())); + delete loader; +#endif + } } #endif plugins->clear(); |