我试过
ModelIndexList list = ui->treeView->selectionModel()->selectedRows();
uint size = list.size();
if (size>0) {
for (int i = size - 1; i >= 0; --i) {
QModelIndex index = proxyModel->mapToSource(list[i]);
standardItemModel->removeRow(index.row());
}
如果选择根行,它会删除带子节点的行。如果我选择了一些子树,那么只删除root并尝试再次删除成为root应用程序崩溃的子项。
答案 0 :(得分:0)
我在removeRow函数中缺少父参数。正确的代码在这里:
ModelIndexList list = ui->treeView->selectionModel()->selectedRows();
uint size = list.size();
if (size>0) {
for (int i = size - 1; i >= 0; --i) {
QModelIndex index = proxyModel->mapToSource(list[i]);
standardItemModel->removeRow(index.row()
/*I was missing this -->*/ , index.parent());
}