summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2021-10-14 09:47:36 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-15 07:36:49 +0000
commit432bab96bc3b8b92797fdfc35368869a0e7f6976 (patch)
tree1387be14fc21953657687b9dc9c0cff7b566c1b6
parent367ef5cebde581c9da9f78f703d8606237d252c7 (diff)
Fix segfault in QItemSelectionModel::hasSelection
Amends 0c2125458a9fdddaf3385b257ba4350da872a1d1. The code assumed that a QItemSelectionModel always has a model. But during initialization from QML, it hasn't. Fixes: QTBUG-97475 Change-Id: Ie9c680f8989a23ef732faaf5da7ef7ae273126aa Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit dbc434dc090df6c475a336cb95e3524150ca7bae) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index ad24b5c9d8..6e1fbabd9d 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -1738,8 +1738,11 @@ bool QItemSelectionModel::hasSelection() const
// d->ranges here. It sorts itself in executePendingOperations,
// thus preventing the sort to happen inside of selectionIsEmpty below.
// Sad story, read more in QTBUG-94546
- auto model_p = static_cast<const QAbstractItemModelPrivate *>(QObjectPrivate::get(model()));
- model_p->executePendingOperations();
+ const QAbstractItemModel *model = QItemSelectionModel::model();
+ if (model != nullptr) {
+ auto model_p = static_cast<const QAbstractItemModelPrivate *>(QObjectPrivate::get(model));
+ model_p->executePendingOperations();
+ }
if (d->currentCommand & (Toggle | Deselect)) {
QItemSelection sel = d->ranges;