aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-09-30 14:54:36 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-10-02 07:35:46 +0200
commit7fa397156c831b410b551c2ad84d17f2eaf9e5c6 (patch)
treee796e631023ad92b06889eb96a5b01b4874157d7 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent98399d9d57fb601da9b7eaba3cc100039dfc4356 (diff)
QtQml: Fix assigning to QML-defined list properties
Returning an invalid QVariant from toVariant() is not helpful. We can't produce a QQmlListReference in that case because there is no object, but a QObjectList works just fine. Writing to list properties via the metaobject is very much supported. We can easily implement it using the same technique we use for reading. Finally, to get the signal counts right, we also need to compare the lists before assignment when taking the QQmlProperty code path. Pick-to: 6.10 6.8 Fixes: QTBUG-140690 Change-Id: I09d6412f3f2ec86144810f47d0d620b63dfcd280 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index c4c3846513..43b6e99f73 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -101,6 +101,7 @@ private slots:
void deduplicateConversionOrigins();
void destroyAndToString();
void detachOnAssignment();
+ void detachedListAssignment();
void detachedReferences();
void dialogButtonBox();
void disappearingArrowFunction();
@@ -1780,6 +1781,33 @@ void tst_QmlCppCodegen::detachOnAssignment()
QCOMPARE(p->things()[0], QStringLiteral("c"));
}
+void tst_QmlCppCodegen::detachedListAssignment()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/detachedListAssignment.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+ QCOMPARE(o->property("changes").toInt(), 0);
+
+ QTest::ignoreMessage(QtDebugMsg, "Return value (l): 2");
+ QTest::ignoreMessage(QtDebugMsg, "root.testProp before assigning l: 0");
+ QTest::ignoreMessage(QtDebugMsg, "root.testProp after assigning l: 2");
+ QMetaObject::invokeMethod(o.data(), "testF");
+
+ // Changes only once in total, not once per element added
+ QCOMPARE(o->property("changes").toInt(), 1);
+
+ QTest::ignoreMessage(QtDebugMsg, "Return value (l): 2");
+ QTest::ignoreMessage(QtDebugMsg, "root.testProp before assigning l: 2");
+ QTest::ignoreMessage(QtDebugMsg, "root.testProp after assigning l: 2");
+ QMetaObject::invokeMethod(o.data(), "testG");
+
+ // No further changes: The lists stay the same
+ QCOMPARE(o->property("changes").toInt(), 1);
+}
+
void tst_QmlCppCodegen::detachedReferences()
{
QQmlEngine engine;