[solved] QtSql and XAMPP MySql - "QMYSQLdriver not loaded"



  • Hi, I' ve installed XAMPP and i've created a database but i get error while opening it.

    Here is my programm:

    QCoreApplication a(argc, argv);
    
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("people");
    db.setUserName("root");
    db.setPassword("");
    
    if(db.open())  qDebug() << "Opened";
    else qDebug() << "Not opened";
    
    return a.exec();
    

    i get en error:

    QsqlDatabase: QMYSQL driver not loaded
    QsqlDatabase: available drivers ... QMYSQL...
    

    So, the driver is installed byt it wont work.

    What is wrong ?



  • Hi and welcome to devnet,

    I think there are a lot of similar threads in the forum; BTW the first thing to check is if the MySQL client library (not the Qt driver) is available in the PATH.

    QSqlDatabase::drivers() return the list on Qt drivers installed on the machine.
    When you try to use a driver, it needs to load the native DB client library; if the client library cannot be loaded the driver loading fails.

    This is why you can see the driver as available but you're not able to load it.



  • "BTW the first thing to check is if the MySQL client library (not the Qt driver) is available in the PATH."

    It is not. This is my PATH.

    PATH=C:\Documents and Settings\All Users\Dane aplikacji\Oracle\Java\javapath;
    D:\aplikacje\Borland\CBUILD~1\Bin ;
    D : \Ap1ikacje\Borland\CBUILD~1\Projects\Bp1;
    C:\WINDOWS\system32;
    C:\WINDOWS ;
    C:\WINDOWS\system32\wbem;
    C:\PROGRAM FILES\QUICKTIME\QTSYSTEM;
    D:\Aplikacje\Internet Explorer;
    C:\Program Files\QuickTime \QTSystem;

    I've tried to use the code below(in cmd) but it still don't work...

     set PATH=C:\xampp\mysql


  • Hi,

    you need to set it as System environmental variable



  • Ok. I did it using this tutorial:
    http://www.computerhope.com/issues/ch000549.htm#windowsxp

    but QT still gives the same error...


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What does QSqlDatabase::lastError() return ?



  • it returns:

    "QSqlError<"", "Driver not loaded", "Driver not loaded">"



  • HI,

    can you show again your PATH? Is the mysqlclient.dll in the PATH?



  • PATH=C:\Documents and Settings\All Users\Dane aplikacji\Oracle\Java\javapath;
    D:\aplikacje\Borland\CBUILD~1\Bin ;
    D : \Ap1ikacje\Borland\CBUILD~1\Projects\Bp1;
    C:\WINDOWS\system32;
    C:\WINDOWS ;
    C:\WINDOWS\system32\wbem;
    C:\PROGRAM FILES\QUICKTIME\QTSYSTEM;
    D:\Aplikacje\Internet Explorer;
    C:\Program Files\QuickTime \QTSystem;
    C:\xampp\mysql;

    I've added the folder with mysql in xampp. Is it wrong?

    i've searched for mysqlclient.dll in xampp file but it is not there.

    There are only mysqlclient.lib files in .../xampp/lib and .../xampp/lib/debug



  • you need to add C:\xampp\lib in the PATH



  • Ok. It works fine now.

    Thank You :)



  • You're welcome.
    Don't forget to mark the thread as SOLVED


Log in to reply
 

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