I've subclassed both of the subject line classes in order to create a simple tree where the user can drag and drop the nodes to rearrange the tree. Everything was working fine until I wanted to essentially "reload" the tree (in case of a database change, for instance). Now the program is unstable and will crash at random, I believe because my QModelIndex.internalPointer()s become invalid (I found one pointing to a random place in memory in the QAbstractItemModel.parent() implementation).

The thing is, I am not saving QModelIndexes anywhere in my code and the program is crashing in the event loop during calls to parent(). So I do not understand how the pointers become invalid.

To reload the tree, I am deleting and recreating the underlying tree entirely and then emitting signal layoutChanged(). I feel this must be where I am messing up.

Anyway, I have no idea where to look really, and I can't just post my entire code. How would you go about switching the underlying tree?