diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-28 13:34:12 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-30 14:18:17 +0200 |
commit | 4cdf0643b442a57b0cf0dcef104e71c0196dba06 (patch) | |
tree | 53d809ab1b42070c435c8325856e71ec30799255 /src/qml/qml/qqmlengine_p.h | |
parent | 041b326fe6f5b98bf4f808976bdfc1a8d5aaeede (diff) |
QtQml: Key singletons by singleton instance info
We can keep the singleton instance info the same across multiple types
created in a single registration call. The result is that we only get
one singleton instance per engine, rather than separate ones for each
version. If you invoke qmlRegisterSingletonType separately, you still
get separate instances, though.
[ChangeLog][QtQml][Important Behavior Changes] The QML engine will now
refrain from creating separate instances of a singleton type for each
version it is registered for if the singleton is registered
declaratively (using QML_SINGLETON). The behavior of procedurally
registered singletons (using the qmlRegisterSingletonType() family of
functions) remains the same: For each registration call, a separate
singleton instance is created.
Task-number: QTBUG-116432
Change-Id: Ic8a5de0f88ef530670cfd81b192201a8ab49b2f7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlengine_p.h')
-rw-r--r-- | src/qml/qml/qqmlengine_p.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index f7da8d5c72..44aad96384 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -252,10 +252,12 @@ public: } private: - class SingletonInstances : private QHash<QQmlType, QJSValue> + class SingletonInstances : private QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue> { public: - void convertAndInsert(QV4::ExecutionEngine *engine, const QQmlType &type, QJSValue *value) + void convertAndInsert( + QV4::ExecutionEngine *engine, const QQmlType::SingletonInstanceInfo::ConstPtr &type, + QJSValue *value) { QJSValuePrivate::manageStringOnV4Heap(engine, value); insert(type, *value); @@ -263,11 +265,11 @@ private: void clear() { - const auto canDelete = [](QObject *instance, const auto &type) -> bool { + const auto canDelete = [](QObject *instance, const auto &siinfo) -> bool { if (!instance) return false; - if (!type.singletonInstanceInfo()->url.isEmpty()) + if (!siinfo->url.isEmpty()) return true; const auto *ddata = QQmlData::get(instance, false); @@ -287,11 +289,11 @@ private: delete instance; } - QHash<QQmlType, QJSValue>::clear(); + QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue>::clear(); } - using QHash<QQmlType, QJSValue>::value; - using QHash<QQmlType, QJSValue>::take; + using QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue>::value; + using QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue>::take; }; SingletonInstances singletonInstances; |