aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-01-14 14:20:57 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-01-15 10:26:22 +0000
commitaca0351c7ce933503b042fd8d745d220c7dd331d (patch)
tree166841d7f6fab2a28ad76236a9ef0dcd50bd98d0 /src/qml/qml
parentf0a9c1efe36b952dfe3e802f3ceeee6ed10a65f5 (diff)
QQmlMetaType: Erase attached properties in dtor
Also, make it more obvious that the attachedPropertyIds are a static member of QQmlTypePrivate. Fixes: QTBUG-72972 Change-Id: If0a28e034dd46d7127993ed15aed11c7641d580e Reviewed-by: Harald Hvaal <harald.hvaal@gmail.com> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmlmetatype.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 11806a89a0..708859be00 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -497,9 +497,9 @@ QQmlType::QQmlType(QQmlMetaTypeData *data, const QString &elementName, const QQm
d->extraData.cd->attachedPropertiesFunc = type.attachedPropertiesFunction;
d->extraData.cd->attachedPropertiesType = type.attachedPropertiesMetaObject;
if (d->extraData.cd->attachedPropertiesType) {
- QHash<const QMetaObject *, int>::Iterator iter = d->attachedPropertyIds.find(d->baseMetaObject);
- if (iter == d->attachedPropertyIds.end())
- iter = d->attachedPropertyIds.insert(d->baseMetaObject, d->index);
+ auto iter = QQmlTypePrivate::attachedPropertyIds.find(d->baseMetaObject);
+ if (iter == QQmlTypePrivate::attachedPropertyIds.end())
+ iter = QQmlTypePrivate::attachedPropertyIds.insert(d->baseMetaObject, d->index);
d->extraData.cd->attachedPropertiesId = *iter;
} else {
d->extraData.cd->attachedPropertiesId = -1;
@@ -569,8 +569,16 @@ QQmlType::QQmlType(QQmlTypePrivate *priv)
QQmlType::~QQmlType()
{
- if (d && !d->refCount.deref())
+ if (d && !d->refCount.deref()) {
+ // If attached properties were successfully registered, deregister them.
+ // (They may not have been registered if some other type used the same baseMetaObject)
+ if (d->regType == CppType && d->extraData.cd->attachedPropertiesType) {
+ auto it = QQmlTypePrivate::attachedPropertyIds.find(d->baseMetaObject);
+ if (it != QQmlTypePrivate::attachedPropertyIds.end() && *it == d->index)
+ QQmlTypePrivate::attachedPropertyIds.erase(it);
+ }
delete d;
+ }
}
QHashedString QQmlType::module() const