diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index ad24b5c9d8f..6e1fbabd9d0 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;