From 96ac9c2599113b045b4f3ea71c4f20ead93a4c41 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 4 May 2023 15:39:57 +0200 Subject: QmlCompiler: Convert thisObject to correct type Amends commit 365b781599993aef933228599eaeb6eb909d9a93. Change-Id: I5775d634ef4e5204cdec2f440b1992b7272866d2 Reviewed-by: Fabian Kosmale --- src/qmlcompiler/qqmljscodegenerator.cpp | 5 ++++- tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 + .../qml/qmlcppcodegen/data/signalsWithLists.qml | 8 ++++++++ tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 24 ++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qmlcppcodegen/data/signalsWithLists.qml 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 varlist: [1, "foo", this, undefined, true] + property list 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({ 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 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 objlist = o->property("objlist").value>(); + 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; -- cgit v1.2.1