Yeah. those tree model based bugs can get irritating. I suggest you use ModelTest to track your bug down. It helped me many a times. http://qt-project.org/wiki/Model_Test
Yeah. those tree model based bugs can get irritating. I suggest you use ModelTest to track your bug down. It helped me many a times. http://qt-project.org/wiki/Model_Test
Thanks for your help!
To recreate the crash i'm experiencing, add a node and 10 subnodes. Select the last subnode and press the delete button until the program segfaults.
I tried to use ModelTest but it doesn't give me any hints unfortunately. Honestly though, i had to modify the test first because it didn't like how the text for each item was dependent on its index. The test assumes an object will have the same text before and after its moved, which is not the case in my example. But after that slight modification, ModelTest doesn't say anything, despite the crash i'm seeing. But the fact that i had to modify ModelTest was what prompted me to ask my question here in the first place, perhaps moving items around in the model the way i am is the reason for my problems, and should be done via say, a QSortFilterProxyModel instead.
This thread is 6 years old but appears in Google, so I'll hint to the probable solution for future readers.
If you move items the way you do it, you will invalidate your view's internal persistentModelIndices for selected items, current item etc. Next time such a persistent index will be fed to your model's data() function, it will segfault.
For sorting / rearranging items you need to either
orQt Code:
beginResetModel(); sortItems(); endResetModel();To copy to clipboard, switch view to plain text mode
Qt Code:
for(row in all items) { toRow = sortRow(row); // or whatever beginMoveRows(row, toRow); moveItem(row, toRow); endMoveRows(); }To copy to clipboard, switch view to plain text mode
Bookmarks