diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-29 11:20:20 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-30 17:14:09 +0100 |
commit | 6a278ea43e7d49d7339206a311a63dc2ee291b01 (patch) | |
tree | e50f4504b49186c7bd3e658bf2078c2e19b55fd7 /tests/auto/qml/qqmlinstantiator | |
parent | 642d531e42fb233709155f8c8feb7d429c48db38 (diff) |
QmlModels: Explicitly clear list data dynamic metaobject
Otherwise it can try to access model objects after they are deleted.
Pick-to: 6.7
Fixes: QTBUG-121588
Change-Id: I4420611be19dc650b7bf29ae805a7477e4c3d7c0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Nicolas Fella <nicolas.fella@kdab.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qqmlinstantiator')
-rw-r--r-- | tests/auto/qml/qqmlinstantiator/data/listDataDestruction.qml | 20 | ||||
-rw-r--r-- | tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp | 12 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlinstantiator/data/listDataDestruction.qml b/tests/auto/qml/qqmlinstantiator/data/listDataDestruction.qml new file mode 100644 index 0000000000..82d707af37 --- /dev/null +++ b/tests/auto/qml/qqmlinstantiator/data/listDataDestruction.qml @@ -0,0 +1,20 @@ +import QtQml + +QtObject { + id: menu + + Component.onCompleted: dt = new Date(); + property date dt + property Instantiator i: Instantiator { + model: { + var model = []; + var d = menu.dt; + model.push({text: "A"}); + return model; + } + delegate: QtObject { + objectName: modelData.text + Component.onCompleted: menu.objectName = objectName + } + } +} diff --git a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp index f6d2752889..6db46d04a8 100644 --- a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp +++ b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp @@ -36,6 +36,8 @@ private slots: void handlerWithParent(); void boundDelegateComponent(); + + void listDataDestruction(); }; tst_qqmlinstantiator::tst_qqmlinstantiator() @@ -308,6 +310,16 @@ void tst_qqmlinstantiator::boundDelegateComponent() QCOMPARE(b->objectAt(2)->objectName(), QStringLiteral("root3")); } +void tst_qqmlinstantiator::listDataDestruction() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("listDataDestruction.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + QCOMPARE(o->objectName(), QLatin1String("A")); +} + class SingleBoolItemModel : public QAbstractListModel { Q_OBJECT |