QT4 does not support MySQL database access by default and requires manual compilation of dynamic Link libraries Qsqlmysqld.dll and qsqlmysql.dll. QT5 supports MySQL database access by default and has generated the above 2 DLL files by default.
QT Access MySQL database, need to keep the two types consistent, if the type is inconsistent, there may be error "Qmysql Driver not Loaded": The following:
The driver Qmysql is already included, but it just can't be loaded.
I use 32-bit QT5, and then customize the installation of 32-bit MySQL, can successfully access the MySQL database. As follows:
The test code is as follows:
QSqlDatabase dbSQL=QSqlDatabase::addDatabase("QMYSQL"); dbSQL.setHostName("localhost");// 主机 dbSQL.setPort(3306);//端口 dbSQL.setDatabaseName("imageprocess");//数据库名字 dbSQL.setUserName("***");//***表示用户名 dbSQL.setPassword("***");//***表示密码 if( dbSQL.open() ) { qDebug()<<"Successfully!!";//如果连接成功,则输出 }
QT Access MySQL Database