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>
This commit is contained in:
Andreas Buhr 2021-10-14 09:47:36 +02:00
parent f08704330d
commit dbc434dc09

View File

@ -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()));
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;