[英]QT/C++ QSqlDatabase: QMYSQL driver not loaded on OS X
I'm using 我正在使用
OS X: 10.12.4 OS X:10.12.4
Qt Creator 4.0.2 Qt Creator 4.0.2
MySQL 5.0.12 (looks like that, not sure) MySQL 5.0.12(看起来像这样,不确定)
C++ C ++
Under from QT I am trying to connect to a mysql database by following code: 在QT下,我试图通过以下代码连接到mysql数据库:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("sql104.rf.gd"); // 185.27.134.10
//db.setPort(3306);
db.setUserName("correctname");
db.setPassword("correctpw");
db.setDatabaseName("rfgd_19926673_shop");
if (db.open()){
ui->label->setText("success");
} else {
i->label->setText("fail");
}
And it fails with 它失败了
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
I've tried this with no result 我尝试了这个没有结果
QPluginLoader loader;
loader.setFileName("/Users/Ivan/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql.dylib");
It returns 它返回
Cannot load library
/Users/Ivan/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/Ivan/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 5): Library not loaded: /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib
Referenced from: /Users/Ivan/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
Reason: image not found)
/Users/Ivan/build-CourierHelperDesktop-Desktop_Qt_5_7_0_clang_64bit-Release/CourierHelperDesktop.app/Contents/MacOS
I've got only 我只有
/usr/local/mysql-5.7.17-macos10.12-x86_64/lib/lib/mysqlclient.20.dylib
Have tried 试过
mkdir /opt/local/lib/mysql55/mysql/
cp /usr/local/mysql-5.7.17-macos10.12-x86_64/lib/lib/mysqlclient.20.dylib /opt/local/lib/mysql55/mysql
No help. 没有帮助
Please, somebody, help me out. 请有人帮帮我。 I am really stuck. 我真的被困住了。
I had this problem on macOS High Sierra (10.13.4) with: 我在macOS High Sierra(10.13.4)上遇到以下问题:
You were lucky, I didn't get this message at first. 您很幸运,起初我没有收到此消息。 I had to enabled more debugging info by setting a new environment variable called QT_DEBUG_PLUGINS
as 1
on Project Properties > Run . 我必须通过在Project Properties> Run QT_DEBUG_PLUGINS
一个名为QT_DEBUG_PLUGINS
的新环境变量设置为1
来启用更多调试信息。 Executing my application again revealed pretty much the same error message as yours. 再次执行我的应用程序会显示与您几乎相同的错误消息。
To solve the problem, the first thing you need to do is find where libmysqlclient.18.dylib
is located in the computer: 要解决此问题,您需要做的第一件事是找到libmysqlclient.18.dylib
在计算机中的位置:
$ find / -iname libmysqlclient.18.dylib
/usr/local/mysql/lib/libmysqlclient.18.dylib
Great, now find where Qt stores its plugins: 太好了,现在找到Qt存储插件的位置:
$ qmake -query QT_INSTALL_PLUGINS
/Users/karlphillip/Qt/5.10.1/clang_64/plugins
and create a new environment variable on your Terminal with this information to make the next part easier: 并在终端上使用此信息创建新的环境变量,以简化下一部分:
$ export QT_PLUGIN_PATH=`qmake -query QT_INSTALL_PLUGINS`
Finally, go to the sqldrivers
inside Qt plugins directory and update the shared library path with the information you found earlier: 最后,转到Qt plugins目录中的sqldrivers
并使用您先前找到的信息更新共享库路径:
$ cd /Users/karlphillip/Qt/5.10.1/clang_64/plugins/sqldrivers
$ install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib $QT_PLUGIN_PATH/sqldrivers/libqsqlmysql.dylib
Done. 做完了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.