Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
4.6.2
-
None
-
CentOS Release 6.5 (Final) GNU/Linux Kernel 2.6.32-431.1.2.0.1.el6.i686
Description
Documentation recommend to delete old selection model after setModel() call:
QItemSelectionModel *m = view->selectionModel(); view->setModel(new_model); delete m;
But what if old and new models are the same?
#include <QApplication> #include <QDirModel> #include <QItemSelectionModel> #include <QTreeView> int main(int argc, char* argv[]) { QApplication app(argc, argv); QDirModel* model = new QDirModel(); QTreeView* view = new QTreeView(); view->setModel(model); view->show(); QItemSelectionModel* old_selection_model = view->selectionModel(); view->setModel(model); delete old_selection_model; // oops return app.exec(); }
Oops, we got segmentation fault: the old selection model is deleted, but the new one is not created since the old model is the same as the new model.