aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-02-06 12:49:39 +0100
committerUlf Hermann <ulf.hermann@qt.io>2025-02-18 22:43:53 +0000
commit7139e893d04d5ef94f71fc4f0b8ed470fe6a24ba (patch)
tree950f52ac0440c924ce8a41159ff9c4850ecb7370 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent82b326e928186622e25866b5298074dd45be772b (diff)
QmlCompiler: Only import hardcoded builtins by default
At run time, not all the builtins are always available, but only those hardcoded into the parser. If we always import all the builtins at compile time, we introduce subtle errors when they shadow parts of the JavaScript global object. Now the builtins need to be actually imported. We cannot rely on the magic that adds them to the root scope of each document anymore. To this end, they need to become a regular module. The builtins are now loaded using a qmldir, just like any other module. The only thing special about is its "system" attribute which we now take to mean "read jsroot.qmltypes". Furthermore, the builtins get a "static" attribute so that we don't warn about them being unused. Even though they can now technically be unused, we really want people to still import them. Pick-to: 6.9 6.8 Fixes: QTBUG-133461 Change-Id: I322e14ba85c939773d36143ca24e88a7c9db23f5 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 83a31b3f1c..61999b5eec 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -188,6 +188,7 @@ private slots:
void multiLookup();
void multipleCtors();
void namespaceWithEnum();
+ void noBuiltinsImport();
void noQQmlData();
void nonNotifyable();
void notEqualsInt();
@@ -3722,6 +3723,17 @@ void tst_QmlCppCodegen::namespaceWithEnum()
QCOMPARE(o->property("i").toInt(), 2);
}
+void tst_QmlCppCodegen::noBuiltinsImport()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/noBuiltinsImport.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QCOMPARE(o->property("textureSize").value<QSizeF>(), QSizeF(1024, 1024));
+}
+
void tst_QmlCppCodegen::noQQmlData()
{
QQmlEngine engine;