Undefined reference to QMYSQLDriver



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



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



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



  • 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 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 :-)


Log in to reply
 

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