Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Using lastInsertId() functionality with QSqlTableModel

    General and Desktop
    2
    3
    4943
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LizMM 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

      1 Reply Last reply Reply Quote 0
      • Z
        ZapB 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.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply Reply Quote 0
        • L
          LizMM last edited by

          Yes that works. Thanks!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post