#include #include #include class tree_model : public QAbstractItemModel { bool crash = false; public: tree_model () {} ~tree_model () {} void set_crash () { crash = true; } virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const override { if (parent.isValid ()) return {}; return createIndex (row, column, nullptr); } virtual QModelIndex parent (const QModelIndex& child) const override { return {}; } virtual int rowCount (const QModelIndex& parent = QModelIndex()) const override { if (parent.isValid ()) return 0; return 10; } virtual int columnCount (const QModelIndex& parent = QModelIndex()) const override { return 1; } virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const override { if (crash) *(int *)0 = 0; if (role == Qt::DisplayRole) return index.row (); return {}; } }; int main (int argc, char *argv[]) { QApplication app(argc, argv); tree_model model; QTreeView view; view.setModel(&model); view.show(); QTimer::singleShot (1000, [&] { model.set_crash (); view.setModel (nullptr); }); return app.exec(); }