Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Sorting in PostgreSQL
- I have database PostgreSQL on Red Hat Linux.
- Driver QPSQL
- To own component inherited from QWidget and having in itself QTableView model QSqlTableModel is established
At submit change in a database there is a change of an order of lines in model: the line with last changed cell becomes last (below)
In such cases recommend to specify obviously a way of sorting of records by means of a method:
But the given method doesn't work: changes nothing, lines continue to "be dumped" as before.
Advise, please, as it is possible to keep an order of an arrangement of lines of model after submit.
P.S. It's warking on Qt 4.5.3 and QtCreator 1.2.1
why not sort your data by Sql Command? (...order by [FIELD])
Thank you, mohsen :)
It's a pity, but the concept of our project makes desirable not to use SQL level in this case but to stay at model level.
andre last edited by
Perhaps you could use a QSortFilterProxy on top your QSqlTableModel?
as Andre mentioned you have to use QSortFilterProxy to make sorts on fields. But you should note that you're making additional process while database engine can do it faster.
The question has dared: