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. Undefined reference to QMYSQLDriver
Qt 6.11 is out! See what's new in the release blog

Undefined reference to QMYSQLDriver

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.5k 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

    I want to create a connection to an existent MySQL Server. I have already tested if have support and I have. Everything is in the right folder. And in case it's important, I'm using the Qt Creator with Qt 4.7 on Ubuntu. I really hope someone here can help me.
    Thank you in anticipation!

    Here's my code:

    @
    #include <QtGui/QApplication>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QMYSQLDriver>
    #include <QtSql/QtSql>
    #include <QMessageBox>

    bool createConnection(){
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");

    db.setHostName("edu.uni-ulm.de");
    
    db.setDatabaseName("config");
    
    db.setPort(1234);
    
    db.setUserName("xxx");
    
    db.setPassword("zzz");
    
    if (!db.open()){
        QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
        return false;
    }
    return true;
    

    }

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    if (!createConnection())
    return 1;
    return a.exec();
    }
    @

    The .pro file:

    @
    QT += core gui
    QT += sql
    TARGET = Test
    TEMPLATE = app
    SOURCES += main.cpp
    HEADERS += ../../../../../../usr/include/qt4/QtSql/qsql_mysql.h
    ../../../../../../usr/include/mysql/mysql.h
    INCLUDEPATH += "/usr/include/mysql/" \ "/usr/include/qt4/QtSql/"
    LIBS+="-L/usr/lib/mysql"
    @

    And the complete error message:
    /home/melanie/Desktop/Workspace/Qt Test/Test-build-desktop/moc_qsql_mysql.cpp:73: error: undefined reference to `QMYSQLDriver::isIdentifierEscapedImplementation(QString const&, QSqlDriver::IdentifierType) const'

    [EDIT: code formatting, please wrap in @-tags, Volker]
    [EDIT 2: removed username and password for security reasons, Volker]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #2

      Hi and welcome.
      It's so simple connecting to a database on Qt.
      "QSqlDatabase Class Reference":http://developer.qt.nokia.com/doc/qt-4.8/qsqldatabase.html
      "QSqlQuery Class Reference":http://developer.qt.nokia.com/doc/qt-4.8/qsqlquery.html

      "MySQL Database Connection Problem on Linux":http://developer.qt.nokia.com/forums/viewthread/12380/

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        You should build the mysql driver as documented "here":/doc/qt-4.8/sql-driver.html and not just add two headers to your project.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          It works now, but it seems that I have to learn the basics first.

          @Volker, it was already a fake username and password but never the less thanks,

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            [quote author="Naraha" date="1325690941"]It works now, but it seems that I have to learn the basics first.

            @Volker, it was already a fake username and password but never the less thanks,
            [/quote]

            Good to know it works. For fake username/password you'd better use "xxxxx" or "user"/"pass" - this way it's obvious that you didn't paste some real world credentials by accident :-)

            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