ubuntu Linux上Qt 配置疑难杂症

1. Qt 连接mysql程序运行时报如下错误

QSqlDatabase: MYSQL driver not loaded QSqlDatabase:

available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

原因可能是QT安装自带的缺乏libqsqlmysql.so响应的libmysqlclient.so依赖库,用ldd工具查看libqsqlmysql.so依赖是否完整,

如:ldd /home/liser/Qt5.9.4/Tools/QtCreator/lib/Qt/plugins/sqldrivers/libqsqlmysql.so

显示libmysqlclient.so.20 => not found

则需要自己编译生成新的libqsqlmysql.so

步骤如下:

a. 安装libmysqlclient依赖

sudo apt-get install mysql-client libmysqlclient-dev

b. cd /home/liser/Qt5.9.4/5.9.4/Src/qtbase/src/plugins/sqldrivers/mysql

qmake && make

c. 将生成的/home/liser/Qt5.9.4/5.9.4/Src/qtbase/plugins/sqldrivers/libqsqlmysql.so

拷贝到/home/liser/Qt5.9.4/5.9.4/gcc_64/plugins/sqldrivers/和/home/liser/Qt5.9.4/Tools/QtCreator/lib/Qt/plugins/sqldrivers/目录下

d. 重新运行测试程序,成功解决该问题

e.参考文献

你可能感兴趣的:(ubuntu Linux上Qt 配置疑难杂症)