参考了https://blog.csdn.net/u011489205/article/details/90313829 自己改了点
环境:deepin 15.11 + QT5.12.9
问题描述:
- QSqlDatabase: MYSQL driver not loadedQSqlDatabase:available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
解决方法:
sudo apt-get install mysql-client libmysqlclient-dev 我用了 下面的语句 sudo apt-get install libmysql++-dev
sudo find / -name "mysql.h"
sudo find / -name "libmysqlclient.so"
root 进去 sudo /home/jinesc/Qt5.12.9/5.12.9/gcc_64/bin/qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/x86_64-linux-gnu/ -lmysqlclient" mysql.pro sudo make sudo make install 或(mariadb的话) sudo /home/jinesc/Qt5.12.9/5.12.9/gcc_64/bin/qmake "INCLUDEPATH+=/usr/include/mariadb" "LIBS+=-L/usr/lib/x86_64-linux-gnu/ -lmysqlclient" mysql.pro sudo make sudo make install
解决方案:修改上一层目录(这里也就是/home/jinesc/Qt5.12.9/5.12.9/Src/qtbase/src/plugins/sqldrivers)的qsqldriverbase.pri文件中的内容,如下:
QT = core core-private sql-private # For QMAKE_USE in the parent projects. #include($$shadowed($$PWD)/qtsqldrivers-config.pri) include($$shadowed($$PWD)/configure.pri) PLUGIN_TYPE = sqldrivers
TARGET = qsqlmysql HEADERS += $$PWD/qsql_mysql_p.h SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp #把mysql.pro中的 QMAKE_USE += mysql用#注释掉 #QMAKE_USE += mysql OTHER_FILES += mysql.json PLUGIN_CLASS_NAME = QMYSQLDriverPlugin include(../qsqldriverbase.pri)
3)如果遇到步骤2中遇到的问题,解决完以后重新执行步骤1的编译命令。最后会在QT的plugins/sqldrivers目录下(这里是/home/jinesc/Qt5.12.9/5.12.9/gcc_64/plugins/sqldrivers)找到编译好的mysql共享库文件(libqsqlmysql.so)。
发表评论