Search code examples
qtsqlitemodel-view

SQLite view as an argument for QSqlTableModel::setTable()


I want my QTableView connected to QSqlTableModel, to dynamically update itself. SQLite view that I'm going to feed to my QSqlTableModel will be created from a number of SQLite tables with LEFT OUTER JOIN. the idea is to make any changes in those constituent SQLite tables automatically propagate through the SQLite view and QSqlTableModel into the QTableView.

  • Is it okay to pass SQLite views to QSqlTableModel::setTable()?
  • Will the QSqlTableModel and QTableView immediately reflect the changes in the SQLite view?
  • Is there a better way to achieve the goal?

Solution

  • Is there a better way to achieve the goal?

    as of now, i have come to the conclusion that in this case it's better to use

    • an SQLite table instead of an SQLite view because it provides a faster look-up for Q...TableModel,
    • a sublass of QAbstractTableModel instead of QSqlTableModel, so that i can update the source SQLite tables first, then QAbstractTableModel::beginResetModel(), rebuild the joined SQLite table, and finally QAbstractTableModel::endResetModel().