c++ - 删除 QListView 中的选定项目列表

标签 c++ model-view-controller qt4 qlistview

如何在 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/

相关文章:

c++ - 如何在开发机器上重现缺少 Qt 插件的问题?

c++ - 所有 CC_CALLBACK_# 宏之间有什么区别?

c++ - 无法推断出模板参数和指向成员的指针

c# - 如何在MVC中写入文本文件

html - MVC 连续排列元素

c# - Visual Studio MVC3 强类型 View 展示一切

c++ - 如何初始化互斥锁和条件变量

c++ - MinGW/CxxTest 奇怪的错误

c++ - QTextStream stdin readline 不暂停输入

c++ - 声明类类型的 QVector 时出错