Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

QSqlTableModel::setFilter order by _rowid_



  • 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_?


  • Lifetime Qt Champion

    Don't do it in sql but add a QSortFilterProxyModel



  • 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


Log in to reply