如何在 QT 4.6 中删除 QListView 中的选定项目列表。 这样的事情不起作用,迭代器变得无效:
QModelIndexList indexes = ui.listview_files->selectionModel()->selectedIndexes();
foreach(QModelIndex index, indexes)
{
model->removeRow(index.row());
}
removeRows 也不适用,它会删除给定行之后的 N 项。 我使用 QStandardItemModel 来存储项目。
最佳答案
QModelIndexList indexes;
while((indexes = ui.listview_files->selectionModel()->selectedIndexes()).size()) {
model->removeRow(indexes.first().row());
}
关于c++ - 删除 QListView 中的选定项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3325115/