Results 1 to 3 of 3

Thread: How to get rowid from sqlite table using QSqlTableModel?

  1. #1
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to get rowid from sqlite table using QSqlTableModel?

    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:

    Qt Code:
    1. model->record(currentSelection.at(0).row()).value("rowid")
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to get rowid from sqlite table using QSqlTableModel?

    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?

  3. The following user says thank you to ChrisW67 for this useful post:

    joescott (4th August 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get rowid from sqlite table using QSqlTableModel?

    Many thanks ChrisW67

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

Similar Threads

  1. Replies: 1
    Last Post: 13th July 2010, 05:36
  2. Replies: 1
    Last Post: 3rd February 2010, 06:01
  3. QSqlTableModel and SQLite Views
    By Baasie in forum Newbie
    Replies: 0
    Last Post: 2nd September 2009, 15:21
  4. Replies: 1
    Last Post: 3rd May 2009, 10:23
  5. Replies: 2
    Last Post: 23rd February 2008, 01:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.