Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlTableModel::setFilter order by _rowid_

QSqlTableModel::setFilter order by _rowid_

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 446 Views
  • 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.
  • K Offline
    K Offline
    Kot Shrodingera
    wrote on last edited by
    #1

    I have SQLite table without PRIMARY KEY, shown in QTableView. When filter is not set, i get all records, for example

    field1   field2
    ---------------
    item1    info1
    item2    info2
    item3    info3
    item1    info4
    ...
    

    But when I set filter like WHERE field1 IN ('item1', 'item2') result is

    field1   field2
    ---------------
    item1    info1
    item1    info4
    item2    info2
    ...
    

    Instead of wanted

    field1   field2
    ---------------
    item1    info1
    item2    info2
    item1    info4
    ...
    

    As I understand I need to order result by _rowid_, but when I add ' ORDER BY _rowid_' to filter, result is empty. How can I achieve ordering by _rowid_?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Don't do it in sql but add a QSortFilterProxyModel

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kot Shrodingera
        wrote on last edited by Kot Shrodingera
        #3

        If I use QSortFilterProxyModel with QSqlRelationalTableModel, i don't have comboBox editors for foreign keys
        I think the problem is with the QTableView::setItemDelegate, cause it expects model to be QSqlRelationalTableModel, not QSortFilterProxyModel

        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