aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-03-13 15:14:28 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-03-14 18:32:51 +0000
commit4fccb4b590301a2d97b55d0448cd753230a4b34e (patch)
tree872602fd70d4566987514939670ee5c5209c1df3 /src/qml/qml
parentbb6d68703b67e042e2a7254c2ca6a004a1441cc5 (diff)
Fix enum class lookup on Singletons
When we consolidated the code for looking up enums in QQmlType, we exposed ourselves to a bug in initEnums: Not only CppType should be affected by the logic for registering unscoped enums, but also C++ singletons (SingletonType). Amends 4ceb343e7f006972940b6880f974770c02fa6b87 and 4e69f2468ad599b7175f60e08341d37689512c9c. Fix this by consulting the meatobject, if there is one. Ideally, this should probably stored in the QQmlType at type registration time, but that can be cleaned up at a later point. Fixes: QTBUG-123225 Task-number: QTBUG-123294 Pick-to: 6.7.0 Change-Id: I7b09459ce4035acb2566b9550fa844897b1b363a Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 9d19d7e6e3bc28a0a62cebb01a0a562b1c13d12f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmltype.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/qml/qml/qqmltype.cpp b/src/qml/qml/qqmltype.cpp
index ee5ae374e5..782d55980f 100644
--- a/src/qml/qml/qqmltype.cpp
+++ b/src/qml/qml/qqmltype.cpp
@@ -302,6 +302,19 @@ void QQmlTypePrivate::insertEnums(Enums *enums, const QMetaObject *metaObject) c
QSet<QString> localEnums;
const QMetaObject *localMetaObject = nullptr;
+ // ### TODO (QTBUG-123294): track this at instance creation time
+ auto shouldSingletonAlsoRegisterUnscoped = [&](){
+ Q_ASSERT(regType == QQmlType::SingletonType);
+ if (!baseMetaObject)
+ return true;
+ int idx = baseMetaObject->indexOfClassInfo("RegisterEnumClassesUnscoped");
+ if (idx == -1)
+ return true;
+ if (qstrcmp(baseMetaObject->classInfo(idx).value(), "false") == 0)
+ return false;
+ return true;
+ };
+
// Add any enum values defined by this class, overwriting any inherited values
for (int ii = 0; ii < metaObject->enumeratorCount(); ++ii) {
QMetaEnum e = metaObject->enumerator(ii);
@@ -318,12 +331,15 @@ void QQmlTypePrivate::insertEnums(Enums *enums, const QMetaObject *metaObject) c
localEnums.clear();
localMetaObject = e.enclosingMetaObject();
}
+ const bool shouldRegisterUnscoped = !isScoped
+ || (regType == QQmlType::CppType && extraData.cppTypeData->registerEnumClassesUnscoped)
+ || (regType == QQmlType::SingletonType && shouldSingletonAlsoRegisterUnscoped())
+ ;
for (int jj = 0; jj < e.keyCount(); ++jj) {
const QString key = QString::fromUtf8(e.key(jj));
const int value = e.value(jj);
- if (!isScoped || (regType == QQmlType::CppType
- && extraData.cppTypeData->registerEnumClassesUnscoped)) {
+ if (shouldRegisterUnscoped) {
if (localEnums.contains(key)) {
auto existingEntry = enums->enums.find(key);
if (existingEntry != enums->enums.end() && existingEntry.value() != value) {