I tried to get MySQL running with Qt today and I am running into an error when I load the QMYSQL drivers. I am running Windows 8.1 as an OS.
Here is the code of my application:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "my_db_name");
db.setHostName("localhost");
db.setDatabaseName("mydb");
db.setUserName("root");
db.setPassword("testpwd1234");
if (db.open()) {
qDebug() << "Opened!";
} else {
qDebug() << "Error = " << db.lastError();
}
return a.exec();
}
I get the following error running it:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL3
I found multiple solutions for the above error, none of which work for me. Here is a list of stuff I verified/tried:
- Qt5.4mingw491_32pluginssqldrivers should contain
qsqlmysql.dll & qsqlmysqld.dll
- the path to libmysql.dll & libmysqld.dll should be added to the Path
variables OR contained within C:windowsSystem32
- libmysql.dll & libmysqld.dll should be added to
Qt5.4mingw491_32in
- Add Qt5.4mingw491_32pluginssqldrivers to executable
directory of Qt project.
- Add libmysql.dll & libmysqld.dll to executable directory of Qt
project.
I found 3., 4. & 5. to be a little weird, since I would expect installing everything correctly and setting Path variables should not require copying these files around. Anyway, none of the above suggestions worked for me.
I am sort of getting a little frustrated and would appreciate any help.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…