Important: Please read the Qt Code of Conduct -

Sorting in PostgreSQL

  • Hello!

    1. I have database PostgreSQL on Red Hat Linux.
    2. Driver QPSQL
    3. 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:
    QSqlTableModel:: setSort

    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.

  • 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.

  • Dear, Friends!

    The question has dared:

    @Qt (C++)
    modelUI->setSort(0, Qt::AscendingOrder);


  • Solved

Log in to reply