我创建了一个自定义 QAbstractItemModel 派生模型,其中包含一组以树分层方式显示的 XML 数据,这些数据将显示在 QTreeView 中,如下图所示:
http://imageshack.us/photo/my-images/840/xmltreeview.png
该模型已成功通过ModelTest和一些基本的编辑测试。但是,当我尝试对此模型进行一些过滤以便将模型拆分为几个不同的视图时,我遇到了一些问题。我尝试过 QSortFilterProxyModel 并且它崩溃了很多。经过一些修复后,尝试从模型中删除行后它仍然崩溃。
发生崩溃时控制台应用程序会显示以下消息:
ratbr QModelIndex(0,0,0xd162000,CGHXmlModel(0xb197e68)) 0 0
rr QModelIndex(0,0,0xd162000,CGHXmlModel(0xb197e68)) 0 0
这是崩溃发生时的调用堆栈:
0 QSortFilterProxyModelPrivate::index_to_iterator qsortfilterproxymodel.cpp 193 0x0134714b
1 QSortFilterProxyModel::parent qsortfilterproxymodel.cpp 1654 0x0111a677
2 QModelIndex::parent qabstractitemmodel.h 389 0x6a2ad95e
3 QPersistentModelIndex::parent qabstractitemmodel.cpp 347 0x6a1f7320
4 QItemSelectionRange::isValid qitemselectionmodel.h 108 0x01341ea4
5 QItemSelectionModel::isSelected qitemselectionmodel.cpp 1187 0x010f0b58
6 QTreeView::drawRow qtreeview.cpp 1602 0x010db133
7 QTreeView::drawTree qtreeview.cpp 1441 0x010da4f4
8 QTreeView::paintEvent qtreeview.cpp 1274 0x010d9bed
9 QWidget::event qwidget.cpp 8333 0x00c1492d
10 QFrame::event qframe.cpp 557 0x00f8e6bc
11 QAbstractScrollArea::viewportEvent qabstractscrollarea.cpp 1043 …Run Code Online (Sandbox Code Playgroud)