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. Calling 'lastError' with incomplete return type 'QSqlError'
Forum Updated to NodeBB v4.3 + New Features

Calling 'lastError' with incomplete return type 'QSqlError'

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 805 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.
  • L Offline
    L Offline
    lukutis222
    wrote on last edited by
    #1

    I cannot wrap my head around this simple issue. I am working with MYSQL on QT and just trying to connect to my database that is running on the virtual machine. I use the following:

    void MainWindow::ConnectToDB(){
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("192.168.3.146");
        db.setPort(20080);
        db.setDatabaseName("test");
        db.setUserName("name");
        db.setPassword("password");
        bool ok = db.open();
        qDebug("DB open state = %u ",ok);
        if(ok == 0){
            qDebug("error = %s",db.lastError().text());
        }
    }
    

    I cannot print lastError() as it is giving me error:

    error: Calling 'lastError' with incomplete return type 'QSqlError'
    

    I have found other simmillar forum posts:
    https://www.qtcentre.org/threads/51484-QSqlDatabase-lastError()-in-MessageBox

    But this does not seem to fix my issue.

    I think its something silly but I cannot figure it out. Thanks in advance.!

    JonBJ 1 Reply Last reply
    0
    • L lukutis222

      I cannot wrap my head around this simple issue. I am working with MYSQL on QT and just trying to connect to my database that is running on the virtual machine. I use the following:

      void MainWindow::ConnectToDB(){
          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("192.168.3.146");
          db.setPort(20080);
          db.setDatabaseName("test");
          db.setUserName("name");
          db.setPassword("password");
          bool ok = db.open();
          qDebug("DB open state = %u ",ok);
          if(ok == 0){
              qDebug("error = %s",db.lastError().text());
          }
      }
      

      I cannot print lastError() as it is giving me error:

      error: Calling 'lastError' with incomplete return type 'QSqlError'
      

      I have found other simmillar forum posts:
      https://www.qtcentre.org/threads/51484-QSqlDatabase-lastError()-in-MessageBox

      But this does not seem to fix my issue.

      I think its something silly but I cannot figure it out. Thanks in advance.!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @lukutis222
      Not sure whether it depends on what version of Qt you have, because I don't particularly recall seeing this issue, but for QSqlError you need #include <QSqlError>, and if you only have #include <QSqlDatabase> that may not be enough.

      L 1 Reply Last reply
      2
      • JonBJ JonB

        @lukutis222
        Not sure whether it depends on what version of Qt you have, because I don't particularly recall seeing this issue, but for QSqlError you need #include <QSqlError>, and if you only have #include <QSqlDatabase> that may not be enough.

        L Offline
        L Offline
        lukutis222
        wrote on last edited by
        #3

        @JonB

        #include <QSqlError>
        

        Solved the issue. Thank you a lot!

        1 Reply Last reply
        0
        • L lukutis222 has marked this topic as solved on

        • Login

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