Qt database connection: QMYSQL driver not loaded
I'm using Qt 5.5 with MSVC plugin. I want to simply connect to a database. The code is -
Code:
QString databaseName
= "imagedatabase";
db.setHostName(hostName);
db.setDatabaseName(databaseName);
db.setUserName(userName);
db.setPassword(userPass);
bool ok = db.open();
But the following error occurs -
Code:
QSqlDatabase: available drivers
: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
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?
Re: Qt database connection: QMYSQL driver not loaded
Sounds like you haven't read the documentation on How to Create Plugins and Deploying Plugins. And you probably haven't installed the MySQL Connector for C++ either.
Re: Qt database connection: QMYSQL driver not loaded
Well, just for people arriving here in despair, you can ignore this rant, I'm sure you already read the documentation and yes, you don't need MySQL Connector for C++.
You need this in the executable folder: libmysql.dll and qsqlmysql.dll
Re: Qt database connection: QMYSQL driver not loaded
Thank you for your polite and instructive comments. We look forward to your next 2,247 helpful posts over the next 8 years
Re: Qt database connection: QMYSQL driver not loaded
The Qt Mysql plugin should be placed in a directory "sqldrivers" that lives next to the main project executable. This is the app-specific default location searched for SQL plugins. The Mysql runtime library, which is not part of Qt, can be placed anywhere the standard Windows DLL search would look when it loads the plugin dll (on a dev machine this is often on the %PATH). For deployment it is usually most convenient to put it in the "sqldrivers" directory too.
http://doc.qt.io/qt-5/windows-deploy...tml#qt-plugins
If you do not have a full Mysql install to work from the Mysql Connector for C should contain the run time library:
http://dev.mysql.com/downloads/connector/c/