2

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.

Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • The first row is row 0, so that should be the first parameter passed to removeRows() if you want to remove everything. However you say you've tried that. Have you tried removing just one or two rows? i.e. removeRows(0, 1) would just remove the first row. – Simon Hibbs Aug 02 '12 at 16:01
  • a) As of index 0, this was my first guess and I have tried 0/1 with no success b) will try to remove one row only and post the result asap – Horst Walter Aug 02 '12 at 18:07
  • Thanks Simon, got me on the right track – Horst Walter Aug 06 '12 at 10:21

1 Answers1

2

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.
Horst Walter
  • 13,663
  • 32
  • 126
  • 228