QSqlDatabase: QMYSQL driver not loaded



  • I have MYSQL database. When I try to execute a query i get this error:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    How can I solve it?

    Code:
    main.cpp
    @#include <QCoreApplication>
    #include <QDebug>
    #include <QtSql>

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

    QString driver = "QMYSQL";
    
    QSqlDatabase db;
    db = QSqlDatabase::addDatabase(driver,dbName);
    db.setHostName(hostName);
    db.setPort(port);
    db.setDatabaseName(dbName);
    db.setUserName(userName);
    db.setPassword(password);
    
    if (db.open()) {
        qDebug() << "Opened!";
        QSqlQuery *qry = new QSqlQuery(db);
        if (qry->exec&#40;"SELECT * FROM `cechosped_users`"&#41;) {
            qDebug() << "Executed!";
        } else {
            qDebug() << "Error:";
            qDebug() << qry->lastError().text();
        }
    } else {
        qDebug() << "Error:";
        qDebug() << db.lastError().text();
    }
    
    return a.exec&#40;&#41;;
    

    }
    @


  • Moderators

    Hi,

    There are lots of posts related to this problem in this forum. Have a look at those.



  • check another forum like this one
    http://qt-project.org/forums/viewthread/36482 and
    http://qt-project.org/forums/viewthread/36656

    the key is never tired to read !
    ok brother ?!


Log in to reply
 

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