From 79014a1b39a4dca09a9d67de68161b10da4bcdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Mon, 5 Oct 2020 13:40:10 +0200 Subject: QQuickListView: Add autotest so that animated delegate does not crash This is separate from the fix, since the test is supposed to also be merged into dev. (Where the fix was not needed) Task-number: QTBUG-86567 Pick-to: 5.15 Change-Id: I2cf1a4b11eed4fe356588aeff322d3a432f0fe83 Reviewed-by: Ulf Hermann --- .../quick/qquicklistview/data/AnimatedButton.qml | 10 +++++++ .../quick/qquicklistview/data/animatedDelegate.qml | 35 ++++++++++++++++++++++ .../quick/qquicklistview/tst_qquicklistview.cpp | 15 ++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/auto/quick/qquicklistview/data/AnimatedButton.qml create mode 100644 tests/auto/quick/qquicklistview/data/animatedDelegate.qml diff --git a/tests/auto/quick/qquicklistview/data/AnimatedButton.qml b/tests/auto/quick/qquicklistview/data/AnimatedButton.qml new file mode 100644 index 0000000000..19cd580cf5 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/AnimatedButton.qml @@ -0,0 +1,10 @@ +import QtQuick 2.12 + +/* + \qmltype AnimatedButton +*/ +Rectangle { + width: 100 + height: 20 + Behavior on color { ColorAnimation { duration : 300 } } +} diff --git a/tests/auto/quick/qquicklistview/data/animatedDelegate.qml b/tests/auto/quick/qquicklistview/data/animatedDelegate.qml new file mode 100644 index 0000000000..46913d87d7 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/animatedDelegate.qml @@ -0,0 +1,35 @@ +import QtQuick 2.12 + +Item { + width: 640 + height: 480 + + property var moreModel: [myDataModelContainer.createObject(null)] + property Component myDataModelContainer: Component { + QtObject {} + } + + function refreshModel() { + //copy contents of moreModel + var list = moreModel.slice() + + moreModel = [myDataModelContainer.createObject(null), myDataModelContainer.createObject(null)] + + for (var i = 0; i < list.length; i++) { + //console.log("trying to destroy ="+list[i]) + list[i].destroy() + } + } + + ListView { + id: listView + objectName: "listView" + anchors.fill: parent + model: moreModel + focus: true + + delegate: AnimatedButton { + color: ListView.isCurrentItem ? "red" : "black" + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index fbc4b92762..d99459a4af 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -299,6 +299,7 @@ private slots: void requiredObjectListModel(); void clickHeaderAndFooterWhenClip(); + void animatedDelegate(); private: template void items(const QUrl &source); @@ -10102,6 +10103,20 @@ void tst_QQuickListView::clickHeaderAndFooterWhenClip() // QTBUG-85302 QVERIFY(root->property("footerPressed").toBool()); } +void tst_QQuickListView::animatedDelegate() +{ + // QTBUG-86567: Should not crash + QScopedPointer window(createView()); + window->setSource(testFileUrl("animatedDelegate.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + for (int i = 0; i < 100; ++i) { + QMetaObject::invokeMethod(window->rootObject(), "refreshModel"); + QTest::qWait(10); + } +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" -- cgit v1.2.3