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. [SOLVED] Can't log QSqlError

[SOLVED] Can't log QSqlError

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 10.7k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SevenPJ
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on last edited by
      #2

      Probably this error is caused by missing include

      @
      #include <QDebug>
      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SevenPJ
        wrote on last edited by
        #3

        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'

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on last edited by
          #4

          @#include <QSqlError>
          #include <QDebug>@

          Add this. And make sure you have
          @Qt += sql@ in your pro file.


          Declaration of (Platform) independence.

          1 Reply Last reply
          1
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            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.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SevenPJ
              wrote on last edited by
              #6

              Thank's now it works

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rahul Das
                wrote on last edited by
                #7

                Please edit the topic as 'Solved', if it is solved. :)


                Declaration of (Platform) independence.

                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