PDA

View Full Version : How to get rowid from sqlite table using QSqlTableModel?



joescott
4th August 2010, 02:06
Hello,

Is there any way to get the rowid from a Sqlite table's row using QSqlTableModel?
I tried the following line but it didn't works:



model->record(currentSelection.at(0).row()).value("rowid")


Thanks in advance
:)

ChrisW67
4th August 2010, 03:43
Does your table have a column declared "INTEGER PRIMARY KEY" or "INTEGER PRIMARY KEY AUTO_INCREMENT"? If so then these are the rowid value... but then you already have a unique identifier and wouldn't be asking this question.

Since the QSqlTableModel effectively executes "select * from table" and the rowid is not returned in that result then I suspect you are out of luck. For a read-only model you could use QSqlQueryModel and explicitly fetch the rowid.

What do you want to achieve?

joescott
4th August 2010, 13:06
Many thanks ChrisW67

I am going to use an id declared as INTEGER PRIMARY KEY AUTO_INCREMENT to get a unique identifier.