diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-10-05 13:40:10 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2021-02-03 12:01:40 +0000 |
commit | 79014a1b39a4dca09a9d67de68161b10da4bcdef (patch) | |
tree | d6ea0030165663476ce6fb5ee7b67d7ec61f6c41 | |
parent | 0ec209743d53fba031c13ec5c717ca106a6df6ed (diff) |
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 <ulf.hermann@qt.io>
3 files changed, 60 insertions, 0 deletions
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 <class T> 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<QQuickView> 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" |