Results 1 to 8 of 8

Thread: delete row from QSqlTableModel in QTableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: delete row from QSqlTableModel in QTableView

    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.
    Last edited by ChrisW67; 10th November 2010 at 23:18.

  2. The following user says thank you to ChrisW67 for this useful post:

    Al_ (18th March 2011)

Similar Threads

  1. QSqlTableModel and QTableView critics.
    By Avrohom in forum Qt Programming
    Replies: 5
    Last Post: 11th September 2009, 03:17
  2. Replies: 2
    Last Post: 6th January 2009, 20:55
  3. QTableView and QSqlTableModel problem
    By Misenko in forum Qt Programming
    Replies: 5
    Last Post: 19th August 2008, 21:58
  4. QSqlTableModel and QTableView and sorting
    By JeanC in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2008, 13:22
  5. QTableView and QSQLTableModel
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 4th March 2006, 18:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.