From 2cfe1bb09c11432ca5033f9589243e9e62fe9488 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 27 Oct 2017 12:54:57 +0200 Subject: Add a means to unregister custom qml types In cases where Qt is used in a plugin it is possible that a plugin will be unloaded while Qt itself is still loaded and as a result there is a chance that there will be conflicting types registered. Therefore, to ensure that plugins correctly clean up after themselves cleanly, we need to add a means to unregister qml types. This is intended to only be used when the user knows what they are doing. Task-number: QTBUG-56521 Task-number: QTBUG-56532 Change-Id: Ie396e522385004e6e9f3841e04f8072ff29cb15b Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlmetatype.cpp | 21 +++++++++++++++++++++ src/qml/qml/qqmlmetatype_p.h | 2 ++ 2 files changed, 23 insertions(+) (limited to 'src/qml') diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index ac670bdabb..3a0d5c3daf 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -2238,6 +2238,27 @@ QQmlPropertyCache *QQmlMetaType::propertyCache(const QQmlType &type, int minorVe return data->propertyCache(type, minorVersion); } +void qmlUnregisterType(int typeIndex) +{ + QMutexLocker lock(metaTypeDataLock()); + QQmlMetaTypeData *data = metaTypeData(); + { + const QQmlTypePrivate *d = data->types.value(typeIndex).priv(); + if (d) { + removeQQmlTypePrivate(data->idToType, d); + removeQQmlTypePrivate(data->nameToType, d); + removeQQmlTypePrivate(data->urlToType, d); + removeQQmlTypePrivate(data->urlToNonFileImportType, d); + removeQQmlTypePrivate(data->metaObjectToType, d); + for (QQmlMetaTypeData::TypeModules::Iterator module = data->uriToModule.begin(); module != data->uriToModule.end(); ++module) { + QQmlTypeModulePrivate *modulePrivate = (*module)->priv(); + modulePrivate->remove(d); + } + data->types[typeIndex] = QQmlType(); + } + } +} + void QQmlMetaType::freeUnusedTypesAndCaches() { QMutexLocker lock(metaTypeDataLock()); diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index 4bfdf52de1..f5b9beb905 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -75,6 +75,8 @@ class QQmlCompiledData; namespace QV4 { struct String; } +void Q_QML_PRIVATE_EXPORT qmlUnregisterType(int type); + class Q_QML_PRIVATE_EXPORT QQmlMetaType { public: -- cgit v1.2.3