Let me be sure I understand what you want. You want to display data from an SQL query to the user in a QTableView. You want the user to be able to edit the displayed data in table view. You don’t want any changes the user makes to affect the database copy, though... just the information to be used in this instance of the running program. Is that correct?
It strikes me that the simplest way to do that would be to select the data you need into a new, temporary database table, then access that table using a QSqlTableModel (not a QSqlQueryModel).
The first sentence of the documentation for QSqlQueryModel states that it provides a read-only data model. You can’t change data through that model.
You could subclass that model to allow for changing data, but QSqlTableModel already does that. The thing that’s different about your case (if I’ve understood correctly) is that you want to keep the edited values separate from the original table, letting them “override†the values in the database only for the current run of the program, then discarding them. Doing this by subclassing QSqlQueryModel would require building your own mini-database of the changed values and making sure the data function in your subclass returns the edited value when there is one, but falls back to the database value for items that were not edited. In my opinion, it would be much simpler to make a temporary table that can be discarded when your program finishes, then use an editable model (QSqlTableModel) to access that table, unless there is some good reason you can’t use a temporary table.
Bookmarks