Results 1 to 6 of 6

Thread: Update View when deteting record the Model

  1. #1
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Update View when deteting record the Model

    Hi,
    I'm using QSqlTableModel with a QTableView on Qt5.
    When i delete a record ...
    Qt Code:
    1. model->removeRows(view->currentIndex().row(), 1);
    To copy to clipboard, switch view to plain text mode 
    ... i get a exclamation mark in the empty line.
    I solved this by using...
    Qt Code:
    1. model->select();
    To copy to clipboard, switch view to plain text mode 

    Is this the best approach?
    Showldn't the view update autommaticaly?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Update View when deteting record the Model

    Where exactly do you get the exclamation mark ? In the view ?

    Also are you using QAbstractItemModel::beginRemoveRows and QAbstractItemModel::endRemoveRows while removing the rows ?

  3. The following user says thank you to aamer4yu for this useful post:

    aguleo (5th December 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update View when deteting record the Model

    Maybe you have to call submit() after deleting the rows?

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    aguleo (5th December 2013)

  6. #4
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update View when deteting record the Model

    Here ... in the view:
    exclamation.png

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

    Default Re: Update View when deteting record the Model

    You get the "!" in the row header indicating that the row has been scheduled for deletion. The model will not actually remove the row from the database until QSqlTableModel::submit() or QSqlTableModel::submitAll() is called on the model (depends on the model edit strategy) directly or indirectly. I suspect that if you call select() without submit() the changes are likely to be discarded not committed, but I have not done the experiment.

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

    aguleo (5th December 2013)

  9. #6
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update View when deteting record the Model

    The only way i managed to make it work was with the model.select();
    I have not tried the aamer4yu's tip but, for me, the question in this point is why it worked with Qt 4 but not with Qt5!

Similar Threads

  1. Replies: 4
    Last Post: 18th April 2012, 18:11
  2. Proxy model / view update problem
    By pascal123 in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2010, 01:02
  3. how to update a tree view model
    By chow in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 15:27
  4. Replies: 9
    Last Post: 7th November 2006, 15:10
  5. Replies: 6
    Last Post: 20th April 2006, 10:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.