QTreeView: Inserting row to model breaks sorting (QSortFilterProxyModel).

  • Hi,

    I have QTreeView with own QAbstractItemModel implementation, sorted by custom QSortFilterProxyModel.

    Everything works fine, but when I insert new row to original model, sorting goes wrong. New item is added correctly, but it's not sorted until user 2x click to TreeView header...

    TreeView setSortingEnabled is true, dynamicSort is true too.
    beginInsertRows(), endInsertRows() is called, emit dataChanged() from setData ......

    But: when i emit layoutAboutToBeChanged() and layoutChaged() signals, application asserts in qsortfilterproxymodel.cpp on line 193 (function index_to_iterator).
    EDIT: it is not assert, iterator node is 0.

    What's wrong? Thank You for any answer...

  • Did you check if your model is sane with the "model test":http://developer.qt.nokia.com/wiki/Model_Test tool? I know tree models can be particulary hard to get right, and a tool like this (I think there are other versions around in KDE that are even more advanced) is invaluable to help you get it right.

  • Yes I tried this test and it was ok. Maybe, this problem is kind of special case.

    Official example "editabletreemodel" adjusted to using QSortFilterProxyModel have this issue too (new inserted items are not sorted).

  • Interesting... Perhaps you should file a bugreport agains QSFPM?

Log in to reply