aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-04-05 13:30:56 +0200
committerUlf Hermann <ulf.hermann@qt.io>2024-04-05 20:38:07 +0200
commit0d1462b3ae8b7cf7975828afc6009d6934c20608 (patch)
treea81f8d557f182d1aef76a64e7235aa39c3ecfdf2
parent06b3a0e6d26a55ce92351f3239c93d75ecea49d7 (diff)
QmlCompiler: Handle scripts as type lookups on GetLookup
This can happen if you lookup a script from a type namespace. The type lookup already has facilities for handling (or rather rejecting) it. Pick-to: 6.7 6.5 Fixes: QTBUG-123050 Change-Id: I092b1d2f47edc152b4f3967b4eaf4620a81ce5ef Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/NotificationItem.qml7
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/NotificationsUtils.js3
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp11
5 files changed, 24 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 0ccd3c7630..77aed4feae 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -1301,6 +1301,7 @@ void QQmlJSCodeGenerator::generate_GetLookupHelper(int index)
}
case QQmlJSRegisterContent::ScopeAttached:
case QQmlJSRegisterContent::Singleton:
+ case QQmlJSRegisterContent::Script:
case QQmlJSRegisterContent::MetaType: {
generateTypeLookup(index);
return;
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 08ec3ca3e0..45f12ca506 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -54,6 +54,8 @@ set(qml_files
GetOptionalLookupOnQJSValueNonStrict.qml
GetOptionalLookupShadowed.qml
Loopy.qml
+ NotificationItem.qml
+ NotificationsUtils.js
OkType.qml
Panel.qml
Planner.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/NotificationItem.qml b/tests/auto/qml/qmlcppcodegen/data/NotificationItem.qml
new file mode 100644
index 0000000000..fba4df6453
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/NotificationItem.qml
@@ -0,0 +1,7 @@
+import QtQml
+import TestTypes as MobileShell
+
+QtObject {
+ id: notificationItem
+ objectName: MobileShell.NotificationsUtils.determineNotificationHeadingText(notificationItem)
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/NotificationsUtils.js b/tests/auto/qml/qmlcppcodegen/data/NotificationsUtils.js
new file mode 100644
index 0000000000..079270e1b9
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/NotificationsUtils.js
@@ -0,0 +1,3 @@
+function determineNotificationHeadingText(notificationItem) {
+ return "heading";
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 22e04e0df3..980ff1986b 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -112,6 +112,7 @@ private slots:
void functionLookup();
void functionReturningVoid();
void functionTakingVar();
+ void getLookupOfScript();
void getOptionalLookup();
void getOptionalLookup_data();
void getOptionalLookupOnQJSValueNonStrict();
@@ -2110,6 +2111,16 @@ void tst_QmlCppCodegen::functionTakingVar()
QCOMPARE(o->property("c"), QVariant::fromValue<int>(11));
}
+void tst_QmlCppCodegen::getLookupOfScript()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/NotificationItem.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->objectName(), u"heading"_s);
+}
+
void tst_QmlCppCodegen::getOptionalLookup_data()
{
QTest::addColumn<QString>("propertyName");