aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlimport.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-06-26 09:33:37 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-10-16 12:38:24 +0200
commit8c614803451ead4ef186d3992dc8fd8d0b93fa37 (patch)
tree8f5454f1a318cce7ee3b53678cacd1a029f31b81 /src/qml/qml/qqmlimport.cpp
parent3f96bf1f43252daf26ed61df2b3456f2dc81183b (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/qml/qqmlimport.cpp')
-rw-r--r--src/qml/qml/qqmlimport.cpp34
1 files changed, 34 insertions, 0 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()