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. Getting primary key after calling QSqlTableModel::submitAll()
QtWS25 Last Chance

Getting primary key after calling QSqlTableModel::submitAll()

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.4k Views
  • 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.
  • S Offline
    S Offline
    scarleton
    wrote on last edited by
    #1

    I am working on a order form, there are two QSqlTableModel's: orderModel and orderItemModel. In both cases the models start off empty. The DB, SQLite, has a AUTOINCREMENT column for the PK. The submitAll() needs to be called on the orderModel first so the orderItemModel foreign key can be set before it is inserted.

    How do I get the primary key from this inserted row?

    In the beforeInsert() slot of the orderModel, the PK column is being set to not be generates so the SQLite’s AUTOINCREMENT can do it thing:

    @
    record.setGenerated(_orderModel->orderIdNo(), false);*
    @

    Side note: I know for an absolute FACT, in the very near feature the DB will be converted over to Firebird, which does NOT have a AUTOINCREMENT concept like most DB’s.
    So ideally if there is a way to get the PK that will work today for SQLite and tomorrow for Firebird, that would be ideal!

    Sam

    1 Reply Last reply
    0
    • S Offline
      S Offline
      scarleton
      wrote on last edited by
      #2

      So I am wondering... Most of my questions on this form get answered pretty quick, if I ask them early in the day, they are normally answered by the end of the day. I am wondering if the reason this has gone unanswered is because it is a unique question or is it simply those that are around don't do a lot of database stuff? I would have figured this is a pretty common question:)

      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