Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlDatabase and QSqlQuery

QSqlDatabase and QSqlQuery

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 316 Views
  • 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 16 Feb 2019, 19:21 last edited by
    #1

    I am implementing database connectivity between a C++ application and a script. The script calls a function in the C++ application to connect to the database, this works and the database connection is established.

    The script attempts to perform a query on the database via the C++ application. I'm not sure how to implement error handling correctly at the moment. The query is very simple:

     SELECT * FROM tblTest
    

    This doesn't appear to return any rows, however if I perform the same query using HeidiSQL on the database, one record is returned.

    How can I tell if there is a problem with the query in the C++ application?

    Kind Regards,
    Sy

    M 1 Reply Last reply 16 Feb 2019, 19:33
    0
    • S SPlatten
      16 Feb 2019, 19:21

      I am implementing database connectivity between a C++ application and a script. The script calls a function in the C++ application to connect to the database, this works and the database connection is established.

      The script attempts to perform a query on the database via the C++ application. I'm not sure how to implement error handling correctly at the moment. The query is very simple:

       SELECT * FROM tblTest
      

      This doesn't appear to return any rows, however if I perform the same query using HeidiSQL on the database, one record is returned.

      How can I tell if there is a problem with the query in the C++ application?

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 16 Feb 2019, 19:33 last edited by
      #2

      @SPlatten
      Hi
      last error is a god starting point
      https://doc.qt.io/qt-5/qsqlquery.html#lastError
      and output its https://doc.qt.io/qt-5/qsqlerror.html#text
      often gives clues if anything it didn't like.

      Also , its important you use next() correctly.

       QSqlQuery query("SELECT * from person ");
          while (query.next()) {
          ..use values
        }
      
      1 Reply Last reply
      2

      1/2

      16 Feb 2019, 19:21

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved