diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-14 17:40:50 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-15 10:18:36 +0100 |
commit | c5a8dc153b3d3218360184837b098ba09018d982 (patch) | |
tree | ab80963e58c4593705cb6a67e441433509029079 /src | |
parent | a07251df7c1e6158cb323e60cb08e687ead15b19 (diff) |
Allow overriding type registrations
Previously if the same revision of the same type was registered multiple
times, the first registration would dominate. Now, the last one does.
[ChangeLog] If you register the same revision of the same type multiple
times, the last registration is the one QML will use. This allows you to
override qmlRegisterSingleton*() calls, for example in order to register
a singleton instance for a type tagged with QML_SINGLETON.
Task-number: QTBUG-79331
Change-Id: I32a2acabc89af6faa89d8ccb6380a473bc8b8ddd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/qqmltypemodule.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/qml/qml/qqmltypemodule.cpp b/src/qml/qml/qqmltypemodule.cpp index 9c9bf3e48f..9d6f269030 100644 --- a/src/qml/qml/qqmltypemodule.cpp +++ b/src/qml/qml/qqmltypemodule.cpp @@ -97,10 +97,14 @@ void QQmlTypeModule::add(QQmlTypePrivate *type) QList<QQmlTypePrivate *> &list = d->typeHash[type->elementName]; for (int ii = 0; ii < list.count(); ++ii) { - Q_ASSERT(list.at(ii)); - if (list.at(ii)->version_min < type->version_min) { + QQmlTypePrivate *in_list = list.at(ii); + Q_ASSERT(in_list); + if (in_list->version_min < type->version_min) { list.insert(ii, type); return; + } else if (in_list->version_min == type->version_min) { + list[ii] = type; + return; } } list.append(type); |