From fa259ed4ff84a5952cdb6d2c6215e92d65afa56a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 17 Apr 2023 12:44:09 +0200 Subject: QmlCompiler: Allow conversion from QQmlListProperty to QList In the happy case this just retrieves the internal QList from the list property. In the sad case it produces a deep copy. That's not worse than what the interpreter does, though. Fixes: QTBUG-112227 Change-Id: I8b2b0ac74c90b6dcee876e83a64502756733c1c5 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index bb9789d63d..37865b8c33 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -178,6 +178,7 @@ private slots: void ambiguousAs(); void boolPointerMerge(); void mergedObjectReadWrite(); + void listConversion(); }; void tst_QmlCppCodegen::initTestCase() @@ -3584,6 +3585,24 @@ void tst_QmlCppCodegen::mergedObjectReadWrite() } } +void tst_QmlCppCodegen::listConversion() +{ + QQmlEngine e; + QQmlComponent c(&e, QUrl(u"qrc:/qt/qml/TestTypes/listConversion.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer o(c.create()); + QVERIFY(!o.isNull()); + + QQmlListProperty list = o->property("o").value>(); + QCOMPARE(list.count(&list), 3); + for (int i = 0; i < 3; ++i) { + QObject *entry = list.at(&list, i); + Person *person = qobject_cast(entry); + QVERIFY(person); + QCOMPARE(person->name(), u"Horst %1"_s.arg(i + 1)); + } +} + QTEST_MAIN(tst_QmlCppCodegen) #include "tst_qmlcppcodegen.moc" -- cgit v1.2.3