报错: QMYSQL driver not loaded
报错:无 QMYSQL
使用
QStringList drivers = QSqlDatabase::drivers(); //获取现在可用的数据库驱动
foreach(QString driver, drivers)
qDebug() << driver;
“QSQLITE”
“QMARIADB”
“QMYSQL”
“QMYSQL3”
“QODBC”
“QODBC3”
“QPSQL”
“QPSQL7”
解决方法:
1.安装mysql去官网下载
修改配置我的在这:D:\qt5.15\setup\5.15.2\Src\qtbase\src\plugins\sqldrivers\mysql、mysql.pro
TARGET = qsqlmysqlHEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp#QMAKE_USE += mysqlOTHER_FILES += mysql.jsonPLUGIN_CLASS_NAME = QMYSQLDriverPlugin
include(../qsqldriverbase.pri)LIBS += -LD:\qt5.15\setup\mysql-8.1.0-winx64\lib -llibmysql
INCLUDEPATH += D:\qt5.15\setup\mysql-8.1.0-winx64\include
DEPENDPATH += D:\qt5.15\setup\mysql-8.1.0-winx64\includeDESTDIR=$$PWD/buidld
修改上级目录中qsqldriverbase.pri:
QT = core core-private sql-private# For QMAKE_USE in the parent projects.
#include($$shadowed($$PWD)/qtsqldrivers-config.pri)
include(./configure.pri)PLUGIN_TYPE = sqldrivers
load(qt_plugin)DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
编译生成:
把它们放入:(我都放进去了,不然很烦)
D:\qt5.15\setup\5.15.2\msvc2019_64\bin
D:\qt5.15\setup\5.15.2\msvc2019_64\lib
D:\qt5.15\setup\5.15.2\msvc2019_64\plugins\sqldrivers
然后把mysql配置到环境变量里:
D:\qt5.15\setup\mysql-8.1.0-winx64\bin
D:\qt5.15\setup\mysql-8.1.0-winx64\lib