summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-05-04 15:39:57 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-05-04 18:59:34 +0200
commit96ac9c2599113b045b4f3ea71c4f20ead93a4c41 (patch)
tree248f8b24b43c8034da0755e53cbcc6746f8b7a96
parent80ed6679cd31165c2bbd2c612e37c2f61e9075a3 (diff)
downloadqtdeclarative-96ac9c2599113b045b4f3ea71c4f20ead93a4c41.tar.gz
QmlCompiler: Convert thisObject to correct type
Amends commit 365b781599993aef933228599eaeb6eb909d9a93. Change-Id: I5775d634ef4e5204cdec2f440b1992b7272866d2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp5
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/signalsWithLists.qml8
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp24
4 files changed, 37 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 66b92dd2f1..5823eb1835 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -2191,7 +2191,10 @@ void QQmlJSCodeGenerator::generate_CreateRestParameter(int argIndex)
void QQmlJSCodeGenerator::generate_ConvertThisToObject()
{
- m_body += changedRegisterVariable() + u" = aotContext->thisObject();\n"_s;
+ m_body += changedRegisterVariable() + u" = "_s
+ + conversion(m_typeResolver->qObjectType(), m_state.changedRegister(),
+ u"aotContext->thisObject()"_s)
+ + u";\n"_s;
}
void QQmlJSCodeGenerator::generate_LoadSuperConstructor()
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index ad8bcf32a9..461c84a76b 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -190,6 +190,7 @@ set(qml_files
signal.qml
signalHandler.qml
signalIndexMismatch.qml
+ signalsWithLists.qml
signatureIgnored.qml
specificParent.qml
storeElementSideEffects.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/signalsWithLists.qml b/tests/auto/qml/qmlcppcodegen/data/signalsWithLists.qml
new file mode 100644
index 0000000000..91967e0bc0
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/signalsWithLists.qml
@@ -0,0 +1,8 @@
+pragma Strict
+import QtQml
+import TestTypes
+
+Person {
+ property list<var> varlist: [1, "foo", this, undefined, true]
+ property list<QtObject> objlist: [this, null, this]
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 20a1bac8af..8f6fdbb004 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -158,6 +158,7 @@ private slots:
void shifts();
void signalHandler();
void signalIndexMismatch();
+ void signalsWithLists();
void signatureIgnored();
void simpleBinding();
void storeElementSideEffects();
@@ -3310,6 +3311,29 @@ void tst_QmlCppCodegen::signalIndexMismatch()
QCOMPARE(visualIndexAfterMoveList, QList<QVariant>({ 0, 1, 2 }));
}
+void tst_QmlCppCodegen::signalsWithLists()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/signalsWithLists.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QVariantList varlist = o->property("varlist").toList();
+ QCOMPARE(varlist.size(), 5);
+ QCOMPARE(varlist[0], QVariant::fromValue(1));
+ QCOMPARE(varlist[1], QVariant::fromValue(u"foo"_s));
+ QCOMPARE(varlist[2], QVariant::fromValue(o.data()));
+ QCOMPARE(varlist[3], QVariant());
+ QCOMPARE(varlist[4], QVariant::fromValue(true));
+
+ QQmlListProperty<QObject> objlist = o->property("objlist").value<QQmlListProperty<QObject>>();
+ QCOMPARE(objlist.count(&objlist), 3);
+ QCOMPARE(objlist.at(&objlist, 0), o.data());
+ QCOMPARE(objlist.at(&objlist, 1), nullptr);
+ QCOMPARE(objlist.at(&objlist, 2), o.data());
+}
+
void tst_QmlCppCodegen::signatureIgnored()
{
QQmlEngine engine;