From 9d0e702b1f29c8120f2000e1558a7b040311d8c0 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 23 Jun 2015 13:13:01 -0500 Subject: Prevent errors when removing items from Repeater that reference parent. Use the same ordering as item views and release before unparenting. Change-Id: I0346342cfcaf9385d8385769795dd5ba35fc43aa Task-number: QTBUG-46828 Reviewed-by: Liang Qi Reviewed-by: Robin Burchell --- .../auto/quick/qquickrepeater/data/modelCleared.qml | 17 +++++++++++++++++ .../quick/qquickrepeater/tst_qquickrepeater.cpp | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/auto/quick/qquickrepeater/data/modelCleared.qml (limited to 'tests') diff --git a/tests/auto/quick/qquickrepeater/data/modelCleared.qml b/tests/auto/quick/qquickrepeater/data/modelCleared.qml new file mode 100644 index 0000000000..1269e9bdf2 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/modelCleared.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Row { + spacing: 2 + height: 100 + + Repeater { + id: repeater + objectName: "repeater" + model: 10 + Rectangle { + color: "green" + width: 10; height: 50 + anchors.bottom: parent.bottom + } + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index 3d0bb8f1ed..559f816a9b 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -68,6 +68,7 @@ private slots: void resetModel(); void modelChanged(); void modelReset(); + void modelCleared(); void properties(); void asynchronous(); void initParent(); @@ -634,6 +635,26 @@ void tst_QQuickRepeater::modelReset() QCOMPARE(addedSpy.count(), 0); } +// QTBUG-46828 +void tst_QQuickRepeater::modelCleared() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("modelCleared.qml")); + + QQuickItem *rootObject = qobject_cast(component.create()); + QVERIFY(rootObject); + + QQuickRepeater *repeater = findItem(rootObject, "repeater"); + QVERIFY(repeater); + + // verify no error messages when the model is cleared and the items are destroyed + QQmlTestMessageHandler messageHandler; + repeater->setModel(0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); + + delete rootObject; +} + void tst_QQuickRepeater::properties() { QQmlEngine engine; -- cgit v1.2.3