summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2021-10-14 09:47:36 +0200
committerAndreas Buhr <andreas.buhr@qt.io>2021-10-14 17:09:20 +0200
commitdbc434dc090df6c475a336cb95e3524150ca7bae (patch)
tree54209442c43e6d5f4a44a504af614cf43f54378f /src/corelib/itemmodels
parentf08704330df1ffbaba5ee78215e5d65f4fb94e1e (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 Pick-to: 6.2 6.2.1 Change-Id: Ie9c680f8989a23ef732faaf5da7ef7ae273126aa Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/itemmodels')
-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;