QStandardItemModel::removeRows() does not work in my use case

丶灬走出姿态 提交于 2019-12-11 03:25:57

问题


Basically I want to delete all rows in my model. I'd prefer to use removeRows(..) instead of clear(), because I want to keep my headers.

I guess I have missed something (docu here), my code is pretty simple:

int c = MainWindow::_viewDataModel->rowCount();
bool r = MainWindow::_viewDataModel->removeRows(0, c);

c e.g. is 4, but r is always false. I have tried 0 and 1 as first index. Using clear() works. The above code has no impact at all.


回答1:


It is working now. After some testing my findings:

  • RemoveRows is very sensitive when there are less rows in the model as I do specify for deletion.
  • In my particular case it did happen that I wanted to delete 5 rows when only 4 rows were still in the model. So _viewDataModel->removeRows(0, 4); does not remove anything at all if there are just 3 rows in the model.
  • Unlike expected in such as case no deletion took place at all.
  • My solution right now is to thoroughly get the model size before deleting.


来源:https://stackoverflow.com/questions/11768266/qstandarditemmodelremoverows-does-not-work-in-my-use-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!