Important: Please read the Qt Code of Conduct -

QSqlError, variable has incomplete type 'const QSqlError' ?

  • I'm trying to connect to an Sql database (MySQL), my code:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    bool blnOpen =;
    if ( blnOpen == true ) {
        pobjScriptEng->evaluate(strOnConnect + "(\"dbConnect(), connected!\");");
    } else {
        const QSqlError err = db.lastError();

    I'm having problems with implement the error handler, I get:

    calling 'lastError' with incomplete return type 'QSqlError' variable has incomplete type 'const QSqlError'

    I can't find an example that does the same sort of thing, what haven't I done?

  • Qt Champions 2019

    @SPlatten said in QSqlError, variable has incomplete type 'const QSqlError' ?:

    what haven't I done?

    Make the class known to the compiler by including it's header

    #include <QSqlError>

  • @Christian-Ehrlicher , thank you, I didn't think the header was required as the type was auto completed when I typed it in, but that has indeed fixed the problem.

Log in to reply