QSqlTableModel submitAll problem



  • Hi All,

    I'm trying to port my MFC app to Qt and I used a lot of QSqlTableModel and QTableView. I am very pleased to find OnRowChange, OnFieldChange and OnManualSubmit as options in QSqlTableModel.

    QSqlTableModel::submitAll calls QSqlTableModel::select at the end of the submit process. This in effect, resets the record cursor.

    Using OnManualSubmit does not pose problem most of the time. However, using OnFieldChange or OnRowChange is pain due to the invalidated cursor. The record sequence displayed in QTableView keep changing whenever a field is updated.

    Can anybody help explain to me how to work around without subclassing the model and view. I hope I don't need to resort to SOCI or OTL database library as I use to when working with MFC.

    Thank you in advance.


  • Moderators

    Disclaimer: I have never seriously used the QSql module...

    Can't you fix the sequence by sorting the results of your query? If you sort e.g. on the key of the record then the sequence should not change anymore. You can just hide the key field from the view and you should be set.

    If all else fails you could try adding a QSortFilterProxy model to fix the sequence of your items.



  • I've tried that. It didn't work so well and I am not comfortable with the result. Lost the currentSelection etc.

    I will use SOCI for now. No time to dig in deeper. I will follow suit. Not to use Qt sql module anymore.



  • Hey, I take back my word. Except for QSqlTableModel. The rest of class in sql module work like a charm.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.