Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
5.11.0
-
None
-
e15fc26e9fdbff141890a3e2e8dc4ef935d022a0
Description
The latest change in QSortFilterProxyModel::setSourceModel() caused a regression bug which breaks QSortFilterProxyModel.
The offending commmit: http://code.qt.io/cgit/qt/qtbase.git/patch/?id=1c0fcbc887459d8963088309e83303eb1a7d2db0
The "destroyed()" signal of the old model is never disconnected. So after you set a new model and delete the old one, QSortFilterProxyModel:: is reset by the destroyed() signal emitted by the old model and the proxy model is broken.
The root cause is you called `_q_sourceModelDestroyed()` manually before calling base class `QAbstractProxyModel::setSourceModel()`, which resets d->model to the static empty model object. So in `QAbstractProxyModel::setSourceModel()`, the following line stop working since it disconnects from the static empty model instead of from the old model object. So the old model is never disconnected.
disconnect(d->model, SIGNAL(destroyed()), this, SLOT(_q_sourceModelDestroyed()));
You can reproduce the bug easily with the test case I attached.
#include <QSortFilterProxyModel> #include <QStandardItemModel> #include <assert.h> int main(int argc, char** argv) { auto proxyModel = new QSortFilterProxyModel(); auto model1 = new QStandardItemModel(); auto model2 = new QStandardItemModel(); proxyModel->setSourceModel(model1); proxyModel->setSourceModel(model2); delete model1; assert(proxyModel->sourceModel() == model2); // the result becomes null while it should be model2 return 0; }
Related discussions in LXQt community: https://github.com/lxqt/libfm-qt/pull/197
Attachments
Issue Links
- duplicates
-
QTBUG-68427 Segfault in subsurface
-
- Closed
-