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: signals for after insert/update/delete and error?
Qt 6.11 is out! See what's new in the release blog

QSqlTableModel: signals for after insert/update/delete and error?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 1.4k 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.
  • L Offline
    L Offline
    lqsa
    wrote on last edited by
    #1

    QSqlTableModel has the signals beforeInsert, beforeUpdate and beforeDelete, but:

    • Is there any signal for afterInsert, afterUpdate and AfterDelete?
    • For insert, QAbstractItemModel::rowsAboutToBeInserted would be the same as beforeInsert?
    • For insert, QAbstractItemModel::rowsInserted was the equivalent to "afterInsert"?
    • What happens if the insert fails? I suppose that first the rowsAboutToBeInserted and beforeInsert are launched, but, if the insert on the db fails, what signal I must to connect to detect it? the rowsInserted are launched?
    JonBJ 1 Reply Last reply
    0
    • L lqsa

      QSqlTableModel has the signals beforeInsert, beforeUpdate and beforeDelete, but:

      • Is there any signal for afterInsert, afterUpdate and AfterDelete?
      • For insert, QAbstractItemModel::rowsAboutToBeInserted would be the same as beforeInsert?
      • For insert, QAbstractItemModel::rowsInserted was the equivalent to "afterInsert"?
      • What happens if the insert fails? I suppose that first the rowsAboutToBeInserted and beforeInsert are launched, but, if the insert on the db fails, what signal I must to connect to detect it? the rowsInserted are launched?
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @lqsa said in QSqlTableModel: signals for after insert/update/delete and error?:

      As you suggest, inherited from the base QAbstractItemModel are signals rowsInserted/Removed(). These are raised after the insertion/deletion.

      Update is a touch different. Assuming by that you mean that values in columns in an existing row are being updated, you would see a QAbstractItemModel::dataChanged() signal.

      For errors/behaviour, don't forget that your QSqlTableModel::EditStrategy determines when the changes are actually submitted to the database and hence when you would actually receive an error if that fails. I use QSqlTableModel::OnManualSubmit, and QSqlTableModel::submitAll() returns a bool and detailed error information. It's a good point and I don't know what the other edit strategies do for errors --- since Qt does not tend to use signals for this --- e.g. QSqlTableModel::OnFieldChange presumably causes the original setData() to return a failure result(?), no idea for QSqlTableModel::OnRowChange!

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        To add to the above, if I'm not mistaken, if the operation on the db fails the opposite signals will be emitted. For example:
        rowsAboutToBeInserted -> rowsInserted -> db operation fails -> rowsAboutToBeRemoved -> rowsRemoved

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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