Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QSqlTableModel question
Qt 6.11 is out! See what's new in the release blog

QSqlTableModel question

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.6k 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.
  • K Offline
    K Offline
    ksukat
    wrote on last edited by
    #1

    Greetings,
    I am using a Postgresql database with my c++ application. My tables have a sequence key field defined. So when you insert a record, it autogens a unique key field value.

    Lets say I have a table in my database called cars, and cars has a key field named car_id that is auto generated.

    I have a variable defined for the cars table called ttable it is of type QSqlTableModel. My question is : When I call the ttable->insertRecord(-1, myRecord), should mRecord NOT have a cars_id field? Or should it be there but with a 0 or negative value?

    thanks for any guidance.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      ksukat
      wrote on last edited by
      #2

      Answer my own question.
      You can leave the cars_id field in the mRecord as insertRecord, followed by submitAll() will do the right thing.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vittalonline
        wrote on last edited by
        #3

        When using auto increment fields you should pass NULL as the value of the auto increment field and the database will fill it with proper number.

        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