QSqlTableModel question

  • 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.

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

  • 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.

Log in to reply

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