I'm using Qt 5.5 with MSVC plugin. I want to simply connect to a database. The code is -
QString databaseName
= "imagedatabase";
db.setHostName(hostName);
db.setDatabaseName(databaseName);
db.setUserName(userName);
db.setPassword(userPass);
bool ok = db.open();
QString hostName = "127.0.0.1";
QString databaseName = "imagedatabase";
QString userName = "demouser";
QString userPass = "demopass";
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(hostName);
db.setDatabaseName(databaseName);
db.setUserName(userName);
db.setPassword(userPass);
bool ok = db.open();
To copy to clipboard, switch view to plain text mode
But the following error occurs -
QSqlDatabase: available drivers
: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
To copy to clipboard, switch view to plain text mode
Then following some suggestion in the web - I copied the qsqlmysql.dll, qsqlmysqld.dll,libmysql.dll, libmysqld.dll files to the project folder. -that didn't work. According to another thread here - I have to put mysqlclient.lib where my application executable is. But I use a wampserver mysql where I don't have a mysqlclient.lib file.
How can I complete this simple task?
Bookmarks