Results 1 to 6 of 6

Thread: QSqlTableModel::beforeUpdate has already updated data

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlTableModel::beforeUpdate has already updated data

    The EditStrategy on this model has been set to OnManualSubmit (if it was set to OnFieldChange I could at least understand the behaviour).

    Qt Code:
    1. connect(model, SIGNAL(beforeUpdate(int,QSqlRecord &)), this, SLOT(rowUpdated(int,QSqlRecord &)));
    2. ---
    3. void MainWindowImpl::rowUpdated(int row, QSqlRecord &record)
    4. {
    5. QString oldname = model->record(row).value(3).toString(),
    6. newname = record.value(3).toString();
    7. qDebug() << oldname << newname;
    8. }
    To copy to clipboard, switch view to plain text mode 

    I get the same 2 new updated strings.
    I can work around by storing the old string each time a row gets selected etc but this is not supposed to be working this way or am I wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlTableModel::beforeUpdate has already updated data

    From what I understand this method is called before changes in the model are submitted into the database, not when the changes in the editor are submited into the model. With that assumption it works exactly as it should. If you want to have access to the data earlier, either subclass the model and reimplement setData() or subclass the delegate and reimplement setModelData().

  3. #3
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel::beforeUpdate has already updated data

    He wysota,

    Thanks for the thorough answer, I looked a while at your suggestions, I understand.

    I have the delegate subclassed to do some custom painting but my workaround is simple and working well, so I won't go through the trouble just now.
    Subclassing the model just for this seems overkill.

    But nice to understand should I need it again, thanks.

    Jean.

  4. #4
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel::beforeUpdate has already updated data

    I decided to go for the setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) approach after all.
    How do I get to the text from QWidget *editor?

    Thanks.

    Quote Originally Posted by wysota View Post
    subclass the delegate and reimplement setModelData().

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlTableModel::beforeUpdate has already updated data

    Cast the editor to the appropriate class using qobject_cast and retrieve the text (like qobject_cast<QLineEdit*>(editor)->text()) or use QObject::property() to fetch the text without casting.

  6. #6
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel::beforeUpdate has already updated data

    Thank you!

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. Replies: 4
    Last Post: 19th October 2007, 19:47
  3. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.