diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-12-12 14:37:46 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-21 08:40:27 +0000 |
commit | 9d0ce63d3297bbc1ecfb29b26ffafa80d6a28fb0 (patch) | |
tree | 5b5bc20c10988727a97c9cfbfa736a2f3a8200b7 /src/qml/qml | |
parent | 37468f383c3fd6f16714ea8861c4632ed855bde0 (diff) |
QML: Consider all possible metatypes when looking for attached props
metaObjectToType is in fact a MultiHash. There can be more than one QML
type associated with a given metaobject. Therefore, in order to find the
attached properties we need to iterate them.
This highlights a different problem: If you register the same metaobject
under different QML names and define different attached properties for
each, you will get random results here. That, however, is a problem of
the public qmlAttachedPropertiesObject function, which doesn't take a
parameter for the registered name of the type.
Change-Id: I0eb9618114029ef5000d8eb12691b7f8de485121
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 083917d20f..c05ae27b93 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -2150,11 +2150,14 @@ int QQmlMetaType::attachedPropertiesFuncId(QQmlEnginePrivate *engine, const QMet QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); - QQmlType type(data->metaObjectToType.value(mo)); - if (type.attachedPropertiesFunction(engine)) - return type.attachedPropertiesId(engine); - else - return -1; + for (auto it = data->metaObjectToType.constFind(mo), end = data->metaObjectToType.constEnd(); + it != end && it.key() == mo; ++it) { + const QQmlType type(it.value()); + if (type.attachedPropertiesFunction(engine)) + return type.attachedPropertiesId(engine); + } + + return -1; } QQmlAttachedPropertiesFunc QQmlMetaType::attachedPropertiesFuncById(QQmlEnginePrivate *engine, int id) |