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

4th August 2010, 02:06

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:


Thanks in advance

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?

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.