diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-04-17 12:44:09 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-04-24 22:22:14 +0200 |
| commit | fa259ed4ff84a5952cdb6d2c6215e92d65afa56a (patch) | |
| tree | 834b4cc6284ea0e54436d12ad0836e3c27c5c183 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | a7c92814f0ff6e9253c781b90e70ad645f8cd94e (diff) | |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
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<QObject> o(c.create()); + QVERIFY(!o.isNull()); + + QQmlListProperty<QObject> list = o->property("o").value<QQmlListProperty<QObject>>(); + QCOMPARE(list.count(&list), 3); + for (int i = 0; i < 3; ++i) { + QObject *entry = list.at(&list, i); + Person *person = qobject_cast<Person *>(entry); + QVERIFY(person); + QCOMPARE(person->name(), u"Horst %1"_s.arg(i + 1)); + } +} + QTEST_MAIN(tst_QmlCppCodegen) #include "tst_qmlcppcodegen.moc" |
