From 432bab96bc3b8b92797fdfc35368869a0e7f6976 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 14 Oct 2021 09:47:36 +0200 Subject: Fix segfault in QItemSelectionModel::hasSelection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit dbc434dc090df6c475a336cb95e3524150ca7bae) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/itemmodels/qitemselectionmodel.cpp | 7 +++++-- 1 file 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(QObjectPrivate::get(model())); - model_p->executePendingOperations(); + const QAbstractItemModel *model = QItemSelectionModel::model(); + if (model != nullptr) { + auto model_p = static_cast(QObjectPrivate::get(model)); + model_p->executePendingOperations(); + } if (d->currentCommand & (Toggle | Deselect)) { QItemSelection sel = d->ranges; -- cgit v1.2.3