aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2023-11-02 22:14:31 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-11-13 22:22:44 +0000
commitd02351d8debe3c089434ff6baf2caff6be52602a (patch)
tree3a9588d1ffa1a7b040837b3a129704a0f8c5ef22 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parent642b08d15726b461864d6de7246e085f5d046b68 (diff)
Fix crash issue in quick table view control
The quick table view can have both QAbstractItemModel and JS value as its model. The table view release and load the items (or rebuild) when its assigned with new model. The newmodel always be compared with existing model before rebuild via QQuickTableViewPrivate::syncModel. This comparison works with QAbstractItemModel but the same fails with JS model. This patch adds additional validation in QQuickTableViewPrivate::syncModel and QQuickTableViewPrivate::setModel for comparing JS model to avoid rebuild when existing model overwritten with same model again. Fixes: QTBUG-117917 Pick-to: 6.5 6.2 Change-Id: Ic15145c4b8998c68ae6471a2abf4aef727041eea Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 79b34126850c4235a1914e95f8e4235cfddba007) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 215966e4f0..96137877cb 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -277,6 +277,7 @@ private slots:
void resettingRolesRespected();
void checkScroll_data();
void checkScroll();
+ void checkRebuildJsModel();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -7496,6 +7497,32 @@ void tst_QQuickTableView::checkScroll() // QTBUG-116566
QTRY_COMPARE_GT(tableView->contentY(), 20);
}
+void tst_QQuickTableView::checkRebuildJsModel()
+{
+ LOAD_TABLEVIEW("resetJsModelData.qml"); // gives us 'tableView' variable
+
+ // Generate javascript model
+ const int size = 5;
+ const char* modelUpdated = "modelUpdated";
+
+ QJSEngine jsEngine;
+ QJSValue jsArray;
+ jsArray = jsEngine.newArray(size);
+ for (int i = 0; i < size; ++i)
+ jsArray.setProperty(i, QRandomGenerator::global()->generate());
+
+ QVariant jsModel = QVariant::fromValue(jsArray);
+ tableView->setModel(jsModel);
+ WAIT_UNTIL_POLISHED;
+
+ // Model change would be triggered for the first time
+ QCOMPARE(tableView->property(modelUpdated).toInt(), 1);
+
+ // Set the same model once again and check if model changes
+ tableView->setModel(jsModel);
+ QCOMPARE(tableView->property(modelUpdated).toInt(), 1);
+}
+
QTEST_MAIN(tst_QQuickTableView)
#include "tst_qquicktableview.moc"