今天,我想问你一个关于建立司机的问题。我的小QT数据库是这样的:
mainDB = QSqlDatabase::addDatabase("QMYSQL");
mainDB.setHostName("127.0.0.1");
mainDB.setPort(3306);
mainDB.setDatabaseName("Database_Name");
mainDB.setUserName("root"); //create editors account later
mainDB.setPassword("Password"); //so on :)
if(mainDB.open())
qDebug() << "mainDB is open";
else
qDebug() << "mainDB error";
然而,我试图编译它,我收到一个错误:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
我搜索了一下这个东西,并意识到,我还没有使用MySQL为QT构建驱动程序。所以,我在我的cmd上输入了这个:
C:\Qt\5.6\Src\qtbase\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH += C:\Program Files\MySQL\MySQL Server 5.7\include" "LIBS+=C:\Program Files\MySQL\MySQL Server 5.7\lib\libmysql.lib" mysql.pro
(在includepath中我使用了所有包含在MySQL服务器中的路径(例如,一百个h。文件),而在LIBS中我使用了路径到我的libmysql文件)。它汇编得很好,我输入了
mingw32-make
完成我的构建。但它会发现错误:
In file included from main.cpp:36:0:
../../../sql/drivers/mysql/qsql_mysql_p.h:55:19: fatal error: mysql.h: No
such file or directory
#include <mysql.h>
^
compilation terminated.
Makefile.Release:466: recipe for target '.obj/release/main.o' failed
mingw32-make[1]: *** [.obj/release/main.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Qt/5.6/Src/qtbase/src/plugins/sqldrivers/
mysql'
makefile:38: recipe for target 'release-all' failed
mingw32-make: *** [release-all] Error 2
因此,我的C:\ Qt \ 5.6 \ Src \ qtbase \ plugins \ sqldrivers为空。
所以,我想知道,如何修复它?
而且,是的,我确实包含了C:\ Qt \ 5.6 \ mingw49_32 \ bin; C:\ Qt \ Tools \ mingw492_32 \ bin; dirs in system as a&#34; PATH&#34;变量
提前谢谢!