QPersistentModelIndex problems in debug libraries
I'm a developer in a fairy large desktop application using Qt 4.8 and I noticed a problem with removing rows from a model. As soon as a row is removed, the application crashes due to an assert in qabstractmodelindex.cpp:544, indicating a corruption in the persistent model indexes.
We use a tree-like model (similar to a filesystem, with directories and files). The persistent model indexes are stored in data structures mirroring the Qt model. Each such data structure represents a node in the model and stores its persistent model index.
Disabling (i.e. not setting) all the persistent indexes fixes the problem - but of course makes certain things more complicated, which is why I'd like to keep using them.
Disabling (i.e. clearing) some of them, during or just before the row removal, doesn't fix the problem. I tried clearing: (1) the indexes affected by the row deletion (i.e. from the item being removed and following rows) (2) all the items from the parent having a row removed (3) the previous plus the parent's persistent index. No joy, still crashes, no idea why since the other indexes aren't affected at all.
This happens even with the simplest case of removing the single row from a parent.
Then I used the Qt Labs ModelTest to check the model. It doesn't report any errors and, surprisingly, the application works fine, the persistent index invalidation after removal works correctly now.
I also compiled the application in release mode (which links with the release rather than the debug versions of Qt). Again, the problem dissapears.
To me this looks like a bug in the debug libraries. BTW - we use MinGW and gcc 4.6.1.