diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-10-15 14:01:18 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-11-14 14:56:38 +0100 |
| commit | 4d3b4853c9e35dc4c756220c2c0924e20bd407b4 (patch) | |
| tree | 136e7ea4d5869266f4dbf820ef105b776fe17b01 | |
| parent | 88488b1abacc20153c19234f0d3fffa8967b9e99 (diff) | |
CustomParser: Fix enum handling
If we have an import namespace, QQmlTypeNameCache::isValid will always
return true; what we want to check instead is whether the type is valid,
or whether we need to query the namespace.
Amends a363aa3df44da399d2aeb8785608501eae50e600.
Fixes: QTBUG-118879
Change-Id: Iaa9db015979c9454662c6fbcd691dbfb03a3d053
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit cfd7198d167b1208cb351ec907e59fa85ca59ba4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 45d532b788fd0df2c462fed110f50158d8b7a3fb)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
| -rw-r--r-- | src/qml/qml/qqmlcustomparser.cpp | 2 | ||||
| -rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp index b701d2e0a8..a0061365ab 100644 --- a/src/qml/qml/qqmlcustomparser.cpp +++ b/src/qml/qml/qqmlcustomparser.cpp @@ -132,7 +132,7 @@ int QQmlCustomParser::evaluateEnum(const QString &script, bool *ok) const // Allow recursion so that we can find enums from the same document. const QQmlTypeNameCache::Result result = imports.asT2()->query<QQmlImport::AllowRecursion>(scope); - if (result.isValid()) { + if (result.type.isValid()) { type = result.type; } else if (result.importNamespace) { dot = nextDot(dot); diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 806bb604e8..b7dff336af 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -6222,7 +6222,7 @@ class EnumTester : public QObject public: enum Types { - FIRST = 0, + FIRST = 42, SECOND, THIRD }; @@ -6236,13 +6236,18 @@ void tst_qqmllanguage::qualifiedScopeInCustomParser() QQmlEngine engine; QQmlComponent component(&engine); component.setData("import QtQml.Models 2.12\n" + "import QtQml\n" "import scoped.custom.test 1.0 as BACKEND\n" "ListModel {\n" + " id: root\n" + " property int num: -1\n" " ListElement { text: \"a\"; type: BACKEND.EnumTester.FIRST }\n" + " Component.onCompleted: { root.num = root.get(0).type }\n" "}\n", QUrl()); QVERIFY2(component.isReady(), qPrintable(component.errorString())); QScopedPointer<QObject> obj(component.create()); QVERIFY(!obj.isNull()); + QCOMPARE(obj->property("num").toInt(), 42); } void tst_qqmllanguage::checkUncreatableNoReason() |
