PDA

View Full Version : Getting primary key after calling QSqlTableModel::submitAll()



scarleton
8th July 2011, 13:28
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);*