[Qt-interest] QSqlTableModel: How to retrieve a primary key for a new row?

Timo Schmiade the_isz at gmx.de
Tue Mar 2 15:35:34 CET 2010


On 02/03/2010 14:23, Yevgen Yashchenko wrote:
> Hey Timo!
>
> There is a best practice to let each table, no matter what is stored in
> it, have and id field.
> So when you add a new row you can just get that id with
>
> QSqlDriver::LastInsertId
>
> feature. Hope it helps.
>

Hi Yevgen,

thanks for your quick answer. As you may have seen, all my tables
(except the mapping table for which it wouldn't make sense in my eyes)
do have an ID field.

Just to make it clear: Do you suggest I stop using QSqlTableModel's
insertRow() function and instead use QSqlQuerys? Because otherwise I
don't see how I'm supposed to get that last inserted ID. Will this
approach fit the OnManualSubmit EditStrategy?

Again, thanks in advance!



More information about the Qt-interest-old mailing list