diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-11-21 19:40:54 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-11-27 08:29:37 +0100 |
commit | 4dbd70b5a45f4a33e8ab6d4076be612d978a4ef8 (patch) | |
tree | e6478a492c8e622f697125522c984e4f5b91af68 /tests/auto/qml/qqmldelegatemodel | |
parent | 71295f834f8bf9d32c33e4c0614893139664be98 (diff) |
QmlModels: Create dynamic properties on the fly when initializing
When the dynamic meta object is requested we need to verify that all
properties are available. Otherwise we can't look them up.
Fixes: QTBUG-108261
Change-Id: I97101b8902250bf6edd0db12efc45cfa81a9cc54
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmldelegatemodel')
-rw-r--r-- | tests/auto/qml/qqmldelegatemodel/data/requiredModelData.qml | 50 | ||||
-rw-r--r-- | tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp | 20 |
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmldelegatemodel/data/requiredModelData.qml b/tests/auto/qml/qqmldelegatemodel/data/requiredModelData.qml new file mode 100644 index 0000000000..467d60dff8 --- /dev/null +++ b/tests/auto/qml/qqmldelegatemodel/data/requiredModelData.qml @@ -0,0 +1,50 @@ +import QtQml + +DelegateModel { + id: root + + property ListModel singularModel: ListModel { + ListElement { + a: "a" + } + ListElement { + a: "a" + } + } + + property ListModel listModel: ListModel { + ListElement { + a: "a" + b: "b" + } + ListElement { + a: "a" + b: "b" + } + } + + property var array: [ + {a: "a", b: "b"}, {a: "b", b: "b"} + ] + + property QtObject object: QtObject { + property string a: "a" + property string b: "b" + } + + property int n: -1 + + model: { + switch (n) { + case 0: return singularModel + case 1: return listModel + case 2: return array + case 3: return object + } + return undefined; + } + + delegate: QtObject { + required property string a + } +} diff --git a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp index 49a0428a46..c3b184e869 100644 --- a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp +++ b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp @@ -34,6 +34,7 @@ private slots: void nestedDelegates(); void universalModelData(); void typedModelData(); + void requiredModelData(); void deleteRace(); void persistedItemsStayInCache(); void unknownContainersAsModel(); @@ -453,6 +454,25 @@ void tst_QQmlDelegateModel::typedModelData() } +void tst_QQmlDelegateModel::requiredModelData() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("requiredModelData.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + + QQmlDelegateModel *delegateModel = qobject_cast<QQmlDelegateModel *>(o.data()); + QVERIFY(delegateModel); + + for (int i = 0; i < 4; ++i) { + delegateModel->setProperty("n", i); + QObject *delegate = delegateModel->object(0); + QVERIFY(delegate); + const QVariant a = delegate->property("a"); + QCOMPARE(a.metaType(), QMetaType::fromType<QString>()); + QCOMPARE(a.toString(), QLatin1String("a")); + } +} void tst_QQmlDelegateModel::deleteRace() { |