Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlTableModel submitAll problem
Forum Updated to NodeBB v4.3 + New Features

QSqlTableModel submitAll problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xeonn
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xeonn
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xeonn
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved