[SOLVED] Can't log QSqlError
-
Hi,
I'm new to Qt and c++.
I'm using Qt4.8.1 and eclipse.I want to post some data to a database table, but I get an error on execute.
To solve this I need to print out the error message.
But when I build my project I get the following error:
src\alarmdatabase.cpp:201:11: error: invalid use of incomplete type 'struct QDebug'
c:\Qt\qt.4.8.1-32\Desktop\Qt\4.8.1\mingw\include/QtCore/qglobal.h:1762:7: error: forward declaration of 'struct QDebug'
src\alarmdatabase.cpp:201:32: error: invalid use of incomplete type 'struct QSqlError'
c:\Qt\qt.4.8.1-32\Desktop\Qt\4.8.1\mingw\include\QtSql/qsqldatabase.h:57:7: error: forward declaration of 'struct QSqlError'
c:\Qt\qt.4.8.1-32\Desktop\Qt\4.8.1\mingw\include/QtCore/qglobal.h: At global scope:
c:\Qt\qt.4.8.1-32\Desktop\Qt\4.8.1\mingw\include/QtCore/qglobal.h:1765:29: warning: inline function 'QDebug qDebug()' used but never defined [enabled by default]My code is:
@bool AlarmDatabase::addAlarm(const QUuid& userId, const QUuid &alarmId, const QUuid &alarmerId, const QString &name, const QDateTime &alarmTime, const QString &location, const QString &gpsLink) {
QSqlQuery query(mDb);
QSqlRecord record = alarmstorage::record(userId, alarmId, alarmerId, name, alarmTime, location, gpsLink);
QString sql = alarmstorage::insert(mDb.driver(), record);
if (!query.exec(sql)) {
qDebug() << query.lastError();
return false;
} else
return true;
}@What is wrong?
// Seven
-
Oh, sorry I missed that.
Added
@#include <QDebug>@But now I get the folowing error:
src\alarmdatabase.cpp:202:32: error: invalid use of incomplete type 'struct QSqlError'
c:\Qt\qt.4.8.1-32\Desktop\Qt\4.8.1\mingw\include\QtSql/qsqldatabase.h:57:7: error: forward declaration of 'struct QSqlError' -
Look at your error messages closely and try to understand them; they can help you figure out what's wrong. Both times, your compiler said you have incomplete type:
src\alarmdatabase.cpp:201:11: error: invalid use of incomplete type ‘struct QDebug’
src\alarmdatabase.cpp:201:32: error: invalid use of incomplete type ‘struct QSqlError’Incomplete type means that the headers are missing. So, #include the relevant header to fix it.