PDA

View Full Version : layoutChanged()



magland
20th June 2007, 15:23
I've subclassed QAbstractItemModel. Internally I remove some rows from the model, so I use


emit layoutAboutToBeChanged();
... delete my rows ...
emit layoutChanged();


Everything works fine, except sometimes where apparently the QTreeView tries to access one of the internal pointers I have already deleted - then I get a seg fault. I know this is the issue because if I remove the rows but don't delete the internal data, then everything is fine (except for a memory leak of course). It doesn't happen all the time... only when I have recently selected a child of the row I am to delete.

So my question is.... what do I need to do to notify the QTreeView that rows have been removed and internal data has been deleted.

Thanks :)

magland
20th June 2007, 18:32
Based on a hint in Qt docs, I solved the problem... when data is deleted you apparently must clear the associated persistent indexes using



changePersistentIndex(index,QModelIndex()).


So, is this true then whenever you delete data in your QAbstractItemModel, you also need to manually clear the persistent indexes?