database error



  • code::
    #include <QCoreApplication>
    #include <QDebug>
    #include <QtSql/QSqlDatabase>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
    db.setHostName( "localhost" );
    db.setDatabaseName( "qtbook" );
    db.setUserName( "user" );
    db.setPassword( "password" );
    if( db.open() )
    {
        qDebug() << "connected";
    }
    else
    {
        qDebug() << db.lastError();
    }
    

    return a.exec();
    }

    error message::

    1. C:\Users\Pavilion\Documents\QT\Db\main.cpp:20: error: C2027: use of undefined type 'QSqlError'

    2.c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtsql\qsqldatabase.h:43: see declaration of 'QSqlError'

    3.C:\Users\Pavilion\Documents\QT\Db\main.cpp:20: error: C2678: binary '<<' : no operator found which takes a left-hand operand of type 'QDebug' (or there is no acceptable conversion)
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(125): could be 'QDebug &QDebug::operator <<(QTextStreamManipulator)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(120): or 'QDebug &QDebug::operator <<(QTextStreamFunction)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(119): or 'QDebug &QDebug::operator <<(const void *)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(118): or 'QDebug &QDebug::operator <<(const QByteArray &)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(117): or 'QDebug &QDebug::operator <<(QLatin1String)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(116): or 'QDebug &QDebug::operator <<(const QStringRef &)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(115): or 'QDebug &QDebug::operator <<(const QString &)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(114): or 'QDebug &QDebug::operator <<(const char *)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(113): or 'QDebug &QDebug::operator <<(double)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(112): or 'QDebug &QDebug::operator <<(float)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(111): or 'QDebug &QDebug::operator <<(quint64)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(110): or 'QDebug &QDebug::operator <<(qint64)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(109): or 'QDebug &QDebug::operator <<(unsigned long)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(108): or 'QDebug &QDebug::operator <<(long)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(107): or 'QDebug &QDebug::operator <<(unsigned int)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(106): or 'QDebug &QDebug::operator <<(int)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(105): or 'QDebug &QDebug::operator <<(unsigned short)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(104): or 'QDebug &QDebug::operator <<(short)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(103): or 'QDebug &QDebug::operator <<(char)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(102): or 'QDebug &QDebug::operator <<(bool)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qdebug.h(101): or 'QDebug &QDebug::operator <<(QChar)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtsql\qsqldatabase.h(139): or 'QDebug operator <<(QDebug,const QSqlDatabase &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qpoint.h(387): or 'QDebug operator <<(QDebug,const QPointF &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qpoint.h(258): or 'QDataStream &operator <<(QDataStream &,const QPointF &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qpoint.h(198): or 'QDebug operator <<(QDebug,const QPoint &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qpoint.h(98): or 'QDataStream &operator <<(QDataStream &,const QPoint &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qtextstream.h(223): or 'QTextStream &operator <<(QTextStream &,QTextStreamManipulator)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qtextstream.h(220): or 'QTextStream &operator <<(QTextStream &,QTextStreamFunction)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qlocale.h(966): or 'QDebug operator <<(QDebug,const QLocale &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qlocale.h(961): or 'QDataStream &operator <<(QDataStream &,const QLocale &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qvariant.h(842): or 'QDebug operator <<(QDebug,const QVariant::Type)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qvariant.h(535): or 'QDataStream &operator <<(QDataStream &,const QVariant::Type)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qvariant.h(533): or 'QDataStream &operator <<(QDataStream &,const QVariant &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qvariant.h(443): or 'QDebug operator <<(QDebug,const QVariant &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qstringlist.h(253): or 'QDataStream &operator <<(QDataStream &,const QStringList &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qregexp.h(119): or 'QDebug operator <<(QDebug,const QRegExp &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qregexp.h(114): or 'QDataStream &operator <<(QDataStream &,const QRegExp &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qiodevice.h(166): or 'QDebug operator <<(QDebug,QIODevice::OpenMode)'
    c:\qt\qt5.4.0\5.4\msvc2013_64\include\qtcore\qcoreapplication.h(266): or 'QDebug operator <<(QDebug,const MSG &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qobject.h(547): or 'QDebug operator <<(QDebug,const QObject *)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qstring.h(1246): or 'QDataStream &operator <<(QDataStream &,const QString &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qbytearray.h(631): or 'QDataStream &operator <<(QDataStream &,const QByteArray &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64\include\QtCore/qchar.h(543): or 'QDataStream &operator <<(QDataStream &,QChar)'
    while trying to match the argument list '(QDebug, QSqlError)'



  • add library Qsqlerror and try this
    qDebug() << db.lastError().text(); instead of qDebug() << db.lastError();


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.