From a20132c326f6d2c5fec848efb98dd86afb320e2a Mon Sep 17 00:00:00 2001 From: Wang Chuan Date: Sat, 30 Nov 2019 20:03:19 +0800 Subject: QQuickItemView: fix crash when changing model When visible items become invisible, ListView will try to cache them and redisplay these items if necessary. However, we can't cache items when changing to a new model, since the old one will be deleted later Fix by adding a flag to let ListView know we are clearing items and prevent cache unnecessary items Fixes: QTBUG-80203 Change-Id: I50dcd3f0586c93496b143bdad0e59751360501a8 Reviewed-by: Richard Moe Gustavsen --- tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/auto/quick/qquicklistview/tst_qquicklistview.cpp') diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 3976dbc0f0..3687c9416e 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -281,6 +281,7 @@ private slots: void touchCancel(); void resizeAfterComponentComplete(); void moveObjectModelItemToAnotherObjectModel(); + void changeModelAndDestroyTheOldOne(); private: template void items(const QUrl &source); @@ -9158,6 +9159,21 @@ void tst_QQuickListView::moveObjectModelItemToAnotherObjectModel() QVERIFY(!QQuickItemPrivate::get(redRect)->culled); } +void tst_QQuickListView::changeModelAndDestroyTheOldOne() // QTBUG-80203 +{ + QScopedPointer window(createView()); + window->setSource(testFileUrl("changeModelAndDestroyTheOldOne.qml")); + window->resize(640, 480); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickItem *root = window->rootObject(); + QVERIFY(root); + + QVERIFY(QQuickTest::qWaitForItemPolished(root)); + // no crash +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" -- cgit v1.2.3