Possible bug in WAbstractItemModel in removing data
Hello! I need to implement a model for hierarchical tree data so I use WAbstractItemModel and reimplement necessary methods.
All works fine besides removing rows. I call beginRemoveRows() then remove data from model and call endRemoveRows. But after this selection of nodes in WTreeView causes a segfault and/or selection bugs: nodes on which I clicked do not become selected in WTreeView (blue background in bootstrap theme). If instead I just use reset() after removing data from model all works fine, but the problem is WTreeView unexpand all nodes which is critical to me.
I tried absolutely same model in Qt with analogical reimplementation and it works fine both ways (with begin/end remove rows and full reset), so I think there is some bug in WAbstractItemModel.
I attach files of my test project. You can select node in WTreeView, press button to delete node and than try to select other nodes in tree and watch what happens.
Updated by Vitaly Volochay over 7 years ago
I found out the problem. There is no bug in WAbstractItemModel, my model does not work because of WModelIndex createIndex(int row, int column, void *ptr) const.
3rd argument must correspond to parent node unlikely qt where it corresponds to this node. After I reworked my model all words fine.