From e15fc26e9fdbff141890a3e2e8dc4ef935d022a0 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 25 May 2018 21:06:43 +0200 Subject: QSortFilterProxyModel: don't assert when old model gets destroyed When a new model was set with setSourceModel() and the mapping was built up, the destruction of the old model caused a reset in the QSortFilterProxyModel which lead to an empty view or an assertion. Now we properly disconnect the old model again and also clean up the old mapping/persistent indexes when a new source model is set. Task-number: QTBUG-44962 Task-number: QTBUG-67948 Task-number: QTBUG-68427 Change-Id: I2e0612899c210bde3ac0cfa59aefd78269deee5b Reviewed-by: David Faure --- src/corelib/itemmodels/qsortfilterproxymodel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 78093727b8..08279cb244 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -1910,7 +1910,10 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) disconnect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset())); disconnect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset())); - d->_q_sourceModelDestroyed(); + // same as in _q_sourceReset() + d->invalidatePersistentIndexes(); + d->_q_clearMapping(); + QAbstractProxyModel::setSourceModel(sourceModel); connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), -- cgit v1.2.3