aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-10-19 14:35:24 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-11-10 15:00:11 +0100
commit91c6d455595d245445f28d6d1c27c4f2710ef3c3 (patch)
tree87c78aea69c6485e9a18f6ca9cf2fa5830b027c7 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent42065c0e6eba377d775908affdd2a98805712b13 (diff)
QmlCompiler: Allow lists as arguments to methods
Since lists are allowed as property types, you should be able to pass them as arguments to methods, too. For now we only handle QML-defined methods, implemented by adding JavaScript functions to your QML elements. The usual type coercion rules apply if you pass JavaScript arrays to such methods. That is, it usually works. We now resolve properties with the "list" flag to their actual types (QQmlListProperty or QList) already when populating the QQmlJSScope, and store the list types as members of QQmlJSScope rather than as a special map in QQmlJSTypeResolver. This allows us to do the same to lists passed as arguments and simplifies some of the type analysis. Fixes: QTBUG-107171 Change-Id: Idf71ccdc1d59f472c17084a36b5d7879c4d959c0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 1a0d211989..c017ba140f 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -141,6 +141,7 @@ private slots:
void inaccessibleProperty();
void typePropagationLoop();
void signatureIgnored();
+ void listAsArgument();
};
void tst_QmlCppCodegen::initTestCase()
@@ -2750,6 +2751,21 @@ void tst_QmlCppCodegen::signatureIgnored()
QCOMPARE(ignored->property("n").toInt(), 67);
}
+void tst_QmlCppCodegen::listAsArgument()
+{
+ QQmlEngine engine;
+
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/listAsArgument.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+
+ QScopedPointer<QObject> o(c.create());
+ QCOMPARE(o->property("i").toInt(), 4);
+ QCOMPARE(o->property("j").toInt(), 2);
+ QCOMPARE(o->property("i1").toInt(), 2);
+ QCOMPARE(o->property("i2").toInt(), 4);
+ QCOMPARE(o->property("d").value<QObject *>()->objectName(), u"this one"_s);
+}
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"