I need to connect to a MySQL server in a Qt application, so I wrote the following code:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("xxx");
db.setUserName("xxx");
db.setPassword("xxx");
db.setDatabaseName("xxx");
db.open();
Unfortunately, when I'm trying to run this code right from the Qt Creator it gives me the following error right after the addDatabase
function call:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
I tried to print the last error code:
qDebug() << db.lastError().text();
Output
"Driver not loaded Driver not loaded"
Of course, I have a MySQL server installed on the same computer.
Why? What am I doing wrong? How can I fix it?