aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-12-02 16:50:20 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-12-04 14:08:47 +0100
commit41dd68344c3d7d0a6a5afc93ab4a05157bed3d3c (patch)
treecf9a7f5ab064c1fb638be11a3078ec53abcf3e5d /tests
parentc28ec259b7822bb7cfc48f1a1940b41e68b5d3b8 (diff)
QQuickTableView: Clear items before deleting the model
Fixes: QTBUG-71374 Change-Id: I534b7612268bb9407844961267865f490d7ff7b2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/ecmascripttests/qjstest/main.cpp1
-rw-r--r--tests/auto/quick/qquicktableview/data/replaceModelTableView.qml63
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp15
3 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/qml/ecmascripttests/qjstest/main.cpp b/tests/auto/qml/ecmascripttests/qjstest/main.cpp
index 4a3541d892..38736b083d 100644
--- a/tests/auto/qml/ecmascripttests/qjstest/main.cpp
+++ b/tests/auto/qml/ecmascripttests/qjstest/main.cpp
@@ -92,6 +92,7 @@ int main(int argc, char **argv)
int flags = 0;
if (parser.isSet(verbose))
+
flags |= Test262Runner::Verbose;
if (parser.isSet(parallel))
flags |= Test262Runner::Parallel;
diff --git a/tests/auto/quick/qquicktableview/data/replaceModelTableView.qml b/tests/auto/quick/qquicktableview/data/replaceModelTableView.qml
new file mode 100644
index 0000000000..2b17e055a7
--- /dev/null
+++ b/tests/auto/quick/qquicktableview/data/replaceModelTableView.qml
@@ -0,0 +1,63 @@
+import QtQuick 2.14
+import QtQml.Models 2.14
+
+Item {
+ id: root
+ visible: true
+ width: 640
+ height: 480
+
+ property alias tableView: tv
+
+ ObjectModel {
+ id: om
+ Rectangle { height: 30; width: 80; color: "red" }
+ Rectangle { height: 30; width: 80; color: "green" }
+ Rectangle { height: 30; width: 80; color: "blue" }
+ }
+
+ ListModel {
+ id: lm
+ ListElement { name: "1" }
+ ListElement { name: "44"}
+ }
+
+ DelegateModel {
+ id: dm
+ model: ListModel {
+ ListElement { name: "Apple" }
+ ListElement { name: "Orange" }
+ }
+ delegate: Rectangle {
+ height: 25
+ width: 100
+ Text { text: "Name: " + name}
+ }
+ }
+ TableView {
+ id: tv
+ visible: true
+ anchors.fill: parent
+ property int modelId: 0
+
+ model: {
+ switch (modelId) {
+ case 0: return lm;
+ case 1: return om;
+ case 2: return dm;
+ default: return null;
+ }
+ }
+
+ delegate: Rectangle {
+ id: dlg
+ implicitWidth: 40
+ implicitHeight: 20
+ color: "red"
+ Text {
+ text: qsTr("name: " + name)
+ }
+ border.color: "green"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 201cd84931..8591bf4ba5 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -176,6 +176,7 @@ private slots:
void checkSyncView_connect_late_data();
void checkSyncView_connect_late();
void checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable();
+ void replaceModel();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -2700,6 +2701,20 @@ void tst_QQuickTableView::checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable(
QCOMPARE(tableView->columns(), 5);
}
+void tst_QQuickTableView::replaceModel()
+{
+ LOAD_TABLEVIEW("replaceModelTableView.qml");
+
+ tableView->setProperty("modelId", 0);
+ QTRY_COMPARE(tableView->rows(), 2);
+ tableView->setProperty("modelId", 1);
+ QTRY_COMPARE(tableView->rows(), 0);
+ tableView->setProperty("modelId", 2);
+ QTRY_COMPARE(tableView->rows(), 0);
+ tableView->setProperty("modelId", 0);
+ QTRY_COMPARE(tableView->rows(), 2);
+}
+
QTEST_MAIN(tst_QQuickTableView)
#include "tst_qquicktableview.moc"