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
Qt 6.11 is out! See what's new in the release blog

QSqlDatabase and QSqlQuery

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 602 Views 2 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on 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

    mrjjM 1 Reply Last reply
    0
    • SPlattenS SPlatten

      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?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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

      • Login

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