Results 1 to 9 of 9

Thread: Updating QSqlRelationalDelegate/QSqlTableModel/QSqlTableModel when database changes?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    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: Updating QSqlRelationalDelegate/QSqlTableModel/QSqlTableModel when database chang

    At line 44 the row count is 6 (not 5) so Qt is keeping the new row up to this point. I initially suspected the issue was purely that you modify the row and do not provide a valid value for the foreign key column (i.e. a 1, 2, or 3). Even with this value set, I could not make it work using the QSqlRecord approach.

    However, the behaviour is as expected with this code using the model's setData() method:
    Qt Code:
    1. qDebug() << "immediately after insertRow()" << tableModel.rowCount();
    2. tableModel.setData(tableModel.index(0, 1),
    3. QLatin1String("item added by insertRow and setData"));
    4. tableModel.setData(tableModel.index(0, 2), 3);
    5. qDebug() << "immediately before submitAll()" << tableModel.rowCount();
    To copy to clipboard, switch view to plain text mode 
    This approach also fails if the foreign key column is not populated.

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

    Al_ (30th March 2011)

Similar Threads

  1. QSqlTableModel the database does not update
    By Zander87 in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2011, 22:34
  2. Disconnecting from database after using QSqlTableModel
    By RobbieClarken in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2009, 09:51
  3. Replies: 2
    Last Post: 23rd February 2008, 01:58
  4. How to manage QSqlTableModel database operations?
    By Abk in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2007, 10:44
  5. QSqlTableModel Help pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 7th March 2006, 19:40

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.