QTreeview::setModel(nullptr) first calls QHeaderView::setModel and only after that QAbstractItemView::setModel. QHeaderView::setModel emits sectionCountChanged signal leading to QTreeView::updateGeometries call. As QTreeView still thinks it has old model, it starts to ask data from the old model. But if that old model now is broken (e.g contains pointers to deleted objects), it will crash.
Attached example will crash after one second of work inside setModel function.