Using lastInsertId() functionality with QSqlTableModel
-
wrote on 28 Mar 2011, 16:24 last edited by
Hello,
I have a MYSQL database that I am interfacing to using the QSqlTableModel class. This is working out great except for one thing: I dont seem to have the functionality that the simpler QSqlQuery class has and that is the lastInsertId() function.
The lastInsertId function is really useful since I can get back my ID for a row I just inserted to the database.
Does anyone know of a way to get the last inserted ID using the QSqlTableModel?
Thanks,
Liz -
wrote on 28 Mar 2011, 17:26 last edited by
I think that QSqlTableMOdel inherits form QSqlQueryModel which provides access to the QSqlQUery via the query() function. You should be able to call the lastInsertId function on the returned QSqlQuery object.
-
wrote on 28 Mar 2011, 18:36 last edited by
Yes that works. Thanks!
1/3