Qt 5.8 Under Link Mysql (under Windows platform), a friend will appear with this cannot connect error
Qsqldatabase:qmysql Driver not loaded
Qsqldatabase:available drivers:qsqlite qmysql QMYSQL3 qodbc QODBC3 qpsql QPSQL7
The solution is as follows
Depending on the Qt version, 32 and 64, the required drivers are different, in general, regardless of what version of MySQL, 64-bit QT to use 64-bit MySQL driver, 32-bit QT to use the 32-bit MySQL driver, seemingly with the installation of MySQL version did not What relationship Oh ~ ~ ~
We need to copy the/mysql/lib (own Mysql installation directory to find out where we are looking for ourselves) under the directory Libmysql.dll to the/Qt/mingw53_32/bin directory.
The test code is as follows:
Qsqldatabase Dbconn;
Qsqlquery query;
Dbconn = Qsqldatabase::adddatabase ("Qmysql");
Dbconn.sethostname ("localhost");//Host Name
Dbconn.setdatabasename ("Since");//Database name
Dbconn.open ("root", "123456");//username, password, successfully returned 1
query = (qsqlquery) dbconn;
Query.exec ("SELECT * from First");
while (Query.next ())
{
int id = query.value (0). ToInt ();
QString name = Query.value (1). ToString ();
Qdebug () << qstring::number (ID) + ":" + name;
}
The test results are:
Starting E:\since2017\Testmysql\release\Testmysql.exe ...
"0:since"
"1:never"
Before you do the MySQL operation, please make sure that the MySQL service is turned on Oh, the individual blog also strong point in the installation of MySQL to open the network connection, do not know if there is no need, may be remote connection when you need it ~ ~ ~
Thank the Bo Friend for my inspiration, such as the link to MySQL this still have questions can refer to this friend's blog OH
http://blog.csdn.net/cateatapple/article/details/52279168
Http://www.cnblogs.com/hbrw/p/6753849.html
Qt5.8 Link Mysql Error and workaround