2

I am trying to connect to MYSQL Database running on windows , I am using Xampp I used this code to connect to database

 QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setDatabaseName("opencart");
db.setUserName("root");
db.setPassword("");
db.open();

it print the following error message

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE

I also added QT+=sql and when I try to print the drivers :

qDebug()<<QSqlDatabase::drivers();//("QSQLITE") 

how can I establish mysql database connection

1 Answer 1

2

By default only the Sqlite drivers are compiled.

Check your {QT_DIR}\plugins\sqldrivers folder.

If its not there just go to {QTDIR}\src\plugins\sqldrivers\mysql and do the usual qmake, nmake , nmake install.

You will need to copy the .dll to your application's directory or in a place that windows looks for dlls.

Sign up to request clarification or add additional context in comments.

4 Comments

what are usual qmake, nmake ?? can you please be more sprcific
Assuming you have the Qt source code, you'd go into the folder I said. Run qmake and then nmake to build the dll. I don't want to be rude but you ought to know what qmake and nmake are.
none of these paths exists in my case ,I have C:\QtSDK\QtCreator\bin\sqldrivers and it produces deprecated error
So go download the source of qt for your version, run configure with the MySQL option and then nmake. You'll end up with the dll you need. It takes time to compile but it's worth it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.