You can probably assign an invalid (null) model index to it. Although layoutAboutToBeChanged() shouldn't invalidate any indexes as no data gets added or removed, only its position may change.
You can probably assign an invalid (null) model index to it. Although layoutAboutToBeChanged() shouldn't invalidate any indexes as no data gets added or removed, only its position may change.
I'm almost sure that I'm using the layoutToBeChanged() in a wrong way. To clarify a bit what I want to do is: I have a table view that shows files on a server, which the client can assign to a certain item or folder. Once the file gets assigned, it gets removed from the table view (hence, the persistent index would be set back to a non selection).
Changing the persistent index to an empty model index list crashes the Application.
Thank you.
Why are you using persistent indexes in the first place? In 99% of the cases you shouldn't need them at all.
But how do I keep a view from changing it's selection after updating it's data? I'm aware that the selection on a view doesn't move from it's row or column, but sometimes after updating data the order on the view gets resorted.
I'll give a look into that. Thank you.
One more thing... what you might try is to connect a slot to the layoutAboutToBeChanged() signal and use QAbstractItemModel::changePersistentIndex() to update persistent indexes manually if you are able to determine new positions of each of the persistent indexes kept by the model.
I did your first approach and it worked fine. Working with dataChanged(), insertRow() and removeRow() did the trick. As you said, it´s a bit more work, but the end result is great.
Thank you.
Bookmarks