Solved QSqlQuery .lasterror compile error: invalid use of incomplete type 'class QSqlError'
-
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,
Cedric09: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 -
@cdwijs
try adding#include <QSqlError>
;) -
@raven-worx said in QSqlQuery .lasterror compile error: invalid use of incomplete type 'class QSqlError':
#include <QSqlError>
That works, Thanks.