Important: Please read the Qt Code of Conduct -

Virtual Sort never gets called on QAbstractListModel derived class

  • defined

    @virtual void sort (int column, Qt::SortOrder order = Qt::AscendingOrder);@

    It's never called on my model although the model is used correctly, and provides the content for the QListView it's attached to.

    Any ideas why?

  • It depends, how it (the view) is used

    is the view that displays the model, sorted?

    is there a QSFPM (QSortFilterProxyModel) in between?

    do you call it directly?

  • There is no QSortFilterProxyModel. I am using QListView, QAbstractListModel and QAbstractItemDelegate.

    How can the view be sorted? QListView (and its parent classes) doesn't have any sorting. Is there a method I am missing?

    Ideally I don't want to call it directly. I want it to be sorted whenever i make changes like adding items to it. etc.

  • Should I be using a different set of view/model classes if I want automatic sort?

  • By default, a list view is not sorted, so why should it be called if you don't call it? Sort is something that can be used, but if you don't call it, the list v9iew does not!

    In a list view, you have to call sort by hand.

    A table view has a sorting property, as it can sort by different columns.

  • Understood. I can definitely do it manually, Just wanted to know if there was a mechanism by which it'll be called automatically. Thanks for your help.

  • On a table with sortingenabled it would be called automatically, but not on a list view.

Log in to reply