PDA

View Full Version : QAbstractItemModel reset() method



lotek
20th September 2011, 15:43
Hello,

In the QAbstractItemModel Class Reference in the description of the reset() method one can read:

"Use beginResetModel() and endResetModel() instead whenever possible. Use this method only if there is no way to call beginResetModel() before invalidating the model. Otherwise it could lead to unexpected behaviour, especially when used with proxy models."

does it mean, that e.g. deleting some rows from the model I shall do it like this:
...
beginResetModel();
beginRemoveRows(parent, fromIdx, toIdx);
// removing rows
endRemoveRows();
endResetModel();
...

instead of calling:

...
beginRemoveRows(parent, fromIdx, toIdx);
// removing rows
endRemoveRows();
reset();
...

thanks

pkj
20th September 2011, 15:55
Why are you trying to reset the model after removing rows? beginRemoveRows() and endRemoveRows() makes sure that the views connected refresh and show appropriately. reset() invalidates model and causes it re-fetch everything.
You reset when your underlying datastructure has changed or something similar.