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. QSqlQuery .lasterror compile error: invalid use of incomplete type 'class QSqlError'

QSqlQuery .lasterror compile error: invalid use of incomplete type 'class QSqlError'

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

    Hi All,

    I'm trying to insert items into a mysql database. As I'm doing things wrong, I get returnvalue false from q.exec(); I would like to know what the error is, so I copied the construction from here:
    https://doc.qt.io/qt-5/qsqlquery.html#execBatch
    When compiling, I get the following error: invalid use of incomplete type 'class QSqlError'

    What is going on?
    Cheers,
    Cedric

    09:06:06: Running steps for project untitled8...
    09:06:06: Starting: "C:\Qt\5.10.1\mingw53_32\bin\qmake.exe" C:\Users\crldewijs\Desktop\git\untitled8\untitled8.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
    Info: creating stash file C:\Users\crldewijs\Desktop\git\build-untitled8-Desktop_Qt_5_10_1_MinGW_32bit-Debug\.qmake.stash
    09:06:07: The process "C:\Qt\5.10.1\mingw53_32\bin\qmake.exe" exited normally.
    09:06:07: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" qmake_all
    mingw32-make: Nothing to be done for 'qmake_all'.
    09:06:08: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
    09:06:08: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" 
    C:/Qt/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory 'C:/Users/crldewijs/Desktop/git/build-untitled8-Desktop_Qt_5_10_1_MinGW_32bit-Debug'
    C:\Qt\5.10.1\mingw53_32\bin\uic.exe ..\untitled8\mainwindow.ui -o ui_mainwindow.h
    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled8 -I. -IC:\Qt\5.10.1\mingw53_32\include -IC:\Qt\5.10.1\mingw53_32\include\QtWidgets -IC:\Qt\5.10.1\mingw53_32\include\QtGui -IC:\Qt\5.10.1\mingw53_32\include\QtANGLE -IC:\Qt\5.10.1\mingw53_32\include\QtSql -IC:\Qt\5.10.1\mingw53_32\include\QtCore -Idebug -I. -IC:\Qt\5.10.1\mingw53_32\mkspecs\win32-g++  -o debug\main.o ..\untitled8\main.cpp
    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled8 -I. -IC:\Qt\5.10.1\mingw53_32\include -IC:\Qt\5.10.1\mingw53_32\include\QtWidgets -IC:\Qt\5.10.1\mingw53_32\include\QtGui -IC:\Qt\5.10.1\mingw53_32\include\QtANGLE -IC:\Qt\5.10.1\mingw53_32\include\QtSql -IC:\Qt\5.10.1\mingw53_32\include\QtCore -Idebug -I. -IC:\Qt\5.10.1\mingw53_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\untitled8\mainwindow.cpp
    ..\untitled8\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
    ..\untitled8\mainwindow.cpp:17:29: error: invalid use of incomplete type 'class QSqlError'
         qDebug() << q.lastError(); // as per https://doc.qt.io/qt-5/qsqlquery.html#execBatch
                                 ^
    In file included from C:\Qt\5.10.1\mingw53_32\include\QtSql/QSqlDatabase:1:0,
                     from ..\untitled8\mainwindow.cpp:7:
    C:\Qt\5.10.1\mingw53_32\include\QtSql/qsqldatabase.h:49:7: note: forward declaration of 'class QSqlError'
     class QSqlError;
           ^
    Makefile.Debug:822: recipe for target 'debug/mainwindow.o' failed
    mingw32-make[1]: Leaving directory 'C:/Users/crldewijs/Desktop/git/build-untitled8-Desktop_Qt_5_10_1_MinGW_32bit-Debug'
    mingw32-make[1]: *** [debug/mainwindow.o] Error 1
    Makefile:36: recipe for target 'debug' failed
    mingw32-make: *** [debug] Error 2
    09:06:13: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project untitled8 (kit: Desktop Qt 5.10.1 MinGW 32bit)
    When executing step "Make"
    09:06:13: Elapsed time: 00:08.
    

    My program:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2018-07-23T08:59:04
    #
    #-------------------------------------------------
    
    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = untitled8
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    
    SOURCES += \
            main.cpp \
            mainwindow.cpp
    
    HEADERS += \
            mainwindow.h
    
    FORMS += \
            mainwindow.ui
    
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QDebug>
    #include <QtWidgets>
    #include <QWidget>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QSqlQuery q;
        qDebug() << q.lastError(); // as per https://doc.qt.io/qt-5/qsqlquery.html#execBatch
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    My versions:
    Qt 5.10.1 mingw53_32
    Windows 7 Enterprise SP1

    raven-worxR 1 Reply Last reply
    0
    • C cdwijs

      Hi All,

      I'm trying to insert items into a mysql database. As I'm doing things wrong, I get returnvalue false from q.exec(); I would like to know what the error is, so I copied the construction from here:
      https://doc.qt.io/qt-5/qsqlquery.html#execBatch
      When compiling, I get the following error: invalid use of incomplete type 'class QSqlError'

      What is going on?
      Cheers,
      Cedric

      09:06:06: Running steps for project untitled8...
      09:06:06: Starting: "C:\Qt\5.10.1\mingw53_32\bin\qmake.exe" C:\Users\crldewijs\Desktop\git\untitled8\untitled8.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
      Info: creating stash file C:\Users\crldewijs\Desktop\git\build-untitled8-Desktop_Qt_5_10_1_MinGW_32bit-Debug\.qmake.stash
      09:06:07: The process "C:\Qt\5.10.1\mingw53_32\bin\qmake.exe" exited normally.
      09:06:07: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" qmake_all
      mingw32-make: Nothing to be done for 'qmake_all'.
      09:06:08: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
      09:06:08: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" 
      C:/Qt/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
      mingw32-make[1]: Entering directory 'C:/Users/crldewijs/Desktop/git/build-untitled8-Desktop_Qt_5_10_1_MinGW_32bit-Debug'
      C:\Qt\5.10.1\mingw53_32\bin\uic.exe ..\untitled8\mainwindow.ui -o ui_mainwindow.h
      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled8 -I. -IC:\Qt\5.10.1\mingw53_32\include -IC:\Qt\5.10.1\mingw53_32\include\QtWidgets -IC:\Qt\5.10.1\mingw53_32\include\QtGui -IC:\Qt\5.10.1\mingw53_32\include\QtANGLE -IC:\Qt\5.10.1\mingw53_32\include\QtSql -IC:\Qt\5.10.1\mingw53_32\include\QtCore -Idebug -I. -IC:\Qt\5.10.1\mingw53_32\mkspecs\win32-g++  -o debug\main.o ..\untitled8\main.cpp
      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled8 -I. -IC:\Qt\5.10.1\mingw53_32\include -IC:\Qt\5.10.1\mingw53_32\include\QtWidgets -IC:\Qt\5.10.1\mingw53_32\include\QtGui -IC:\Qt\5.10.1\mingw53_32\include\QtANGLE -IC:\Qt\5.10.1\mingw53_32\include\QtSql -IC:\Qt\5.10.1\mingw53_32\include\QtCore -Idebug -I. -IC:\Qt\5.10.1\mingw53_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\untitled8\mainwindow.cpp
      ..\untitled8\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
      ..\untitled8\mainwindow.cpp:17:29: error: invalid use of incomplete type 'class QSqlError'
           qDebug() << q.lastError(); // as per https://doc.qt.io/qt-5/qsqlquery.html#execBatch
                                   ^
      In file included from C:\Qt\5.10.1\mingw53_32\include\QtSql/QSqlDatabase:1:0,
                       from ..\untitled8\mainwindow.cpp:7:
      C:\Qt\5.10.1\mingw53_32\include\QtSql/qsqldatabase.h:49:7: note: forward declaration of 'class QSqlError'
       class QSqlError;
             ^
      Makefile.Debug:822: recipe for target 'debug/mainwindow.o' failed
      mingw32-make[1]: Leaving directory 'C:/Users/crldewijs/Desktop/git/build-untitled8-Desktop_Qt_5_10_1_MinGW_32bit-Debug'
      mingw32-make[1]: *** [debug/mainwindow.o] Error 1
      Makefile:36: recipe for target 'debug' failed
      mingw32-make: *** [debug] Error 2
      09:06:13: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
      Error while building/deploying project untitled8 (kit: Desktop Qt 5.10.1 MinGW 32bit)
      When executing step "Make"
      09:06:13: Elapsed time: 00:08.
      

      My program:

      #-------------------------------------------------
      #
      # Project created by QtCreator 2018-07-23T08:59:04
      #
      #-------------------------------------------------
      
      QT       += core gui sql
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = untitled8
      TEMPLATE = app
      
      # The following define makes your compiler emit warnings if you use
      # any feature of Qt which has been marked as deprecated (the exact warnings
      # depend on your compiler). Please consult the documentation of the
      # deprecated API in order to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS
      
      # You can also make your code fail to compile if you use deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      
      SOURCES += \
              main.cpp \
              mainwindow.cpp
      
      HEADERS += \
              mainwindow.h
      
      FORMS += \
              mainwindow.ui
      
      
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      #include <QDebug>
      #include <QtWidgets>
      #include <QWidget>
      #include <QSqlDatabase>
      #include <QSqlQuery>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QSqlQuery q;
          qDebug() << q.lastError(); // as per https://doc.qt.io/qt-5/qsqlquery.html#execBatch
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      My versions:
      Qt 5.10.1 mingw53_32
      Windows 7 Enterprise SP1

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @cdwijs
      try adding #include <QSqlError>
      ;)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • C Offline
        C Offline
        cdwijs
        wrote on last edited by
        #3

        @raven-worx said in QSqlQuery .lasterror compile error: invalid use of incomplete type 'class QSqlError':

        #include <QSqlError>

        That works, Thanks.

        1 Reply Last reply
        0

        • Login

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