Evan Levesque
Evan Levesque

Reputation: 3213

qt MYSQL Connection on windows doesn't work

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

Upvotes: 2

Views: 1863

Answers (1)

Phil Hannent
Phil Hannent

Reputation: 12317

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.

Upvotes: 2

Related Questions