diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-06-26 09:33:37 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-16 12:38:24 +0200 |
commit | 8c614803451ead4ef186d3992dc8fd8d0b93fa37 (patch) | |
tree | 8f5454f1a318cce7ee3b53678cacd1a029f31b81 /src/qml | |
parent | 3f96bf1f43252daf26ed61df2b3456f2dc81183b (diff) |
Provide methods to query and remove a dynamically loaded plugin
This may be necessary in some corner cases in order to manually manage
memmory for loaded libraries. Also, clear the (static) plugins on
qmlClearTypeRegistrations if !QT_CONFIG(library).
Task-number: QTBUG-76074
Change-Id: Id33d2a4acd7ca94efad53353f8bcb020576c4010
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 34 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport_p.h | 4 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 79e3585202..af6d067fbb 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -2141,6 +2141,40 @@ bool QQmlImportDatabase::importDynamicPlugin(const QString &filePath, const QStr return true; } +bool QQmlImportDatabase::removeDynamicPlugin(const QString &filePath) +{ + StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes(); + QMutexLocker lock(&plugins->mutex); + + auto it = plugins->find(QFileInfo(filePath).absoluteFilePath()); + if (it == plugins->end()) + return false; + + QPluginLoader *loader = it->loader; + if (!loader) + return false; + + if (!loader->unload()) { + qWarning("Unloading %s failed: %s", qPrintable(it->uri), + qPrintable(loader->errorString())); + } + + delete loader; + plugins->erase(it); + return true; +} + +QStringList QQmlImportDatabase::dynamicPlugins() const +{ + StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes(); + QMutexLocker lock(&plugins->mutex); + QStringList results; + for (auto it = plugins->constBegin(), end = plugins->constEnd(); it != end; ++it) { + if (it->loader != nullptr) + results.append(it.key()); + } + return results; +} #endif // QT_CONFIG(library) void QQmlImportDatabase::clearDirCache() diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h index 7f781d2eb7..30d7c56a3e 100644 --- a/src/qml/qml/qqmlimport_p.h +++ b/src/qml/qml/qqmlimport_p.h @@ -203,7 +203,7 @@ private: QQmlImportsPrivate *d; }; -class QQmlImportDatabase +class Q_QML_PRIVATE_EXPORT QQmlImportDatabase { Q_DECLARE_TR_FUNCTIONS(QQmlImportDatabase) public: @@ -214,6 +214,8 @@ public: #if QT_CONFIG(library) bool importDynamicPlugin(const QString &filePath, const QString &uri, const QString &importNamespace, int vmaj, QList<QQmlError> *errors); + bool removeDynamicPlugin(const QString &filePath); + QStringList dynamicPlugins() const; #endif QStringList importPathList(PathType type = LocalOrRemote) const; |