QSqlTableModel caches changes until the submitAll() is called. The way it handles inserts and updates differs from the way it handles deletes. If you have a single model with two views then updates and inserts made in one model are immediately visible in the other view as you would expect. If you remove a row then the row remains in the views with the only thing identifying that the row is scheduled for deletion is the "!" in the header view. This behaviour is unique to the SQL models and does not exist in the in-memory models.
To obtain the behaviour that users expect, i.e. the row disappears when deleted, the views have to either:
- Hide the row based on the undocumented "!" marker. This has to happen in every view displaying the data every time a row is removed.
- Force a submitAll() and commit all changes after delete. All views on the model then lose their selection and current item and you have to make efforts to maintain these (because that is what users expect). You have also lost the ability to revert pending changes.
- Load the table entirely into an in-memory model. Whether this is acceptable is application dependent.
I might have missed something and I'm all ears if someone has the elegant solution.




Reply With Quote
Bookmarks