IMO there could be many things which could lead to the behavior you are observing.
The first thing is that the QAbstractItemModel methods (at-least the virtual ones) are meant to work with each other in reference with QMadelIndex. Now having said that it is difficult to comment or suggest based on the code snippet you posted, as we (at least I) don't know how the the methods implementation looks like.
What do you mean, a segfault occurs in the block of code between beginRemoveRows() and endRemoveRows() or in a slot connected to beginRomoveRows()?A segfault tends to appear in beginRemoveRows with a QModelIndex with an invalid internalPointer.
This makes me assume that the pointer to the parent Node (application specific management item) is stored in any given QModelIndex's internal pointer, am I correct? Further just having pointer to a valid parent (Node) is not enough, what I mean is having the pointer to the correct parent is very essential. Further I wonder how can you be confident about creating nodes with pointers to valid parents when segfault occurs?I'm fairly confident however that i only create nodes with pointers to valid parents.
Yes it is definitely possible to have sorting just using QAbstractItemModel, in fact that is how Qt in-built QSortFilterProxyModel does it.Is it possible to do the sorting in this way or must i add a QSortFilterProxyModel?
I know that my reply is not so constructive but as I see, the information is just enough to ponder about, but not enough to analyze the problem in conclusive manner. Lastly, these will be my first response check points.
1. Check beginRemoveRows() parameters, there is a potential that the parameters are not valid. (As this is where you see a segfault)
2. Indexes are created (I mean in index() method) in a fool proof manner (i.e. all possible parameters values are handled properly)
3. Are you using any persistent indexes, or storing any indexes? If yes then better review them.
Bookmarks