Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. database error
Qt 6.12 LTS is out! See what's new in the release blog

database error

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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)'

    1 Reply Last reply
    0
    • Ayoub_JobA Offline
      Ayoub_JobA Offline
      Ayoub_Job
      wrote on last edited by
      #2

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

      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
      • Unsolved