环境:
ubuntu 14.04LTS
qt5.5.1
mysql
报错:QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
错误描述:
1,首先看qt安装路径:我是/opt/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers目录下有无libsqlmysql.so
有,检查完整性:ldd libsqlmysql.so,若出现not found字样,则此驱动无法使用,需要自己手动编译,若无,则手动编译。
2,qt的安装一定要勾选sorce文件,否则重新安装qt
3,进入目录:我是/opt/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/mysql
4,qmake
5,期间报/usr/bin/ld: cannot find -l****错误
6,解决办法:apt-cache serach lib****-dev查询依赖包,找到后apt-get install lib****-dev进行下载
7,make
8,make install
9,进入目录:我是/opt/Qt5.5.1/5.5/Src/qtbase/plugins/sqldrivers找到libqsqlmysql.so
10,将libqsqlmysql.so复制到/opt/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers
即可解决驱动无法装载的bug