QSqlRelationalTableModel or QSqlQueryModel

  • Hi!

    I use QTableView with database in first form for listing records.
    I create second form (modal form) for editing single record. This record has field, referencing to other table (FK). I tried to use QSqlRelationalTableModel with "setFilter" (for selecting single record) and "setRelation" (for processing FK and combobox). I planned to use "submit" for saving record.
    I didn't have success with this scheme because "setFilter" and "setRelation" are conflicting. I think I should use QSqlQueryModel for selecting single record.

    How should I save record (QSqlQueryModel is read-only)?
    Is this method right and the best for my target?

  • @michaeldev said in QSqlRelationalTableModel or QSqlQueryModel:

    I think I should use QSqlQueryModel for selecting single record

    No, you can just use a QSortFilterProxyModel on the original model and your strategy will work

  • @VRonin Yes, I've try and it works.
    But now I am facing with problem of saving changes. QDataWidgetMapper doesn't update ComboBox after changing.
    I see the same situation here
    And there is bugreport

  • You can still implement what QDataWidgetMapper does manually. I know it's not ideal but it shouldn't be a huge amount of work

  • It is very strange. Components are very raw. At least some of them.

  • @michaeldev said in QSqlRelationalTableModel or QSqlQueryModel:

    Components are very raw

    I wouldn't be that harsh. There are a few bugs here and there and some parts have been more-or-less discontinued (DOM qgraphicsview, etc.) but overall the quality of components in Qt is pretty high

  • Qt Widgets - more alive than dead or more dead than alive?

  • It's a vital part of the framework so I'd say alive

Log in to reply