diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-10-27 12:54:57 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2017-12-01 10:44:08 +0000 |
commit | 2cfe1bb09c11432ca5033f9589243e9e62fe9488 (patch) | |
tree | 84e8249bd024e476efef6ca63d9d443010d6070f /src/qml/qml/qqmlmetatype.cpp | |
parent | 9e7dbbeec0be2ce07c58edf84ce6e03d60946bce (diff) |
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
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()); |