Thanks for replying.
Your solution is not what I am looking for, unfortunately. I do not even have a QSortFilterProxyModel. Specifically, I do not want sorting to happen at the client. I wish it to happen at the server with a ORDER BY. My problem, IIRC, is thatQTableView::setSortingEnabled(true); QTableView::sortByColumn(col, Qt.DescendingOrder);
causes two SQL queries to be sent to the database, one for each line. Reversing the order of the two lines does not help. According to me, it is therefore not possible to enable sorting and pick which column to sort by without executing two queries in a row, which is ridiculously wasteful since we only care about the result of the second query. Users may not even be aware that this is what is happening behind the scenes. There should surely be some way of enabling sorting and specifying the column+direction without issuing two separate queries to the database. Nobody else but me seems to think this is an issue/bad/wrong!
I realise this question is now OT. If you would care to share your help on this matter please be kind enough to post in my original thread, https://forum.qt.io/topic/83294/how-to-prevent-qtableview-qtreeview-doing-query-sorting-multiple-times. Thank you.