Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Sorting in PostgreSQL
Qt 6.11 is out! See what's new in the release blog

Sorting in PostgreSQL

Scheduled Pinned Locked Moved Qt Creator and other tools
7 Posts 3 Posters 4.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MasterMatrix
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #2

      why not sort your data by Sql Command? (...order by [FIELD])

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MasterMatrix
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Perhaps you could use a QSortFilterProxy on top your QSqlTableModel?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mohsen
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MasterMatrix
              wrote on last edited by
              #6

              Dear, Friends!

              The question has dared:

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

              Thanks!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mohsen
                wrote on last edited by
                #7

                Solved

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved