我正在使用
OS X:10.12.4
Qt Creator 4.0.2
MySQL 5.0.12(看起来像那样,不确定)
C++
在 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");
}
它失败了
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
我试过这个没有结果
QPluginLoader loader;
loader.setFileName("/Users/Ivan/Qt/5.7/clang_64/plugins/sqldrivers/libqsqlmysql.dylib");
它返回
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
我只有
/usr/local/mysql-5.7.17-macos10.12-x86_64/lib/lib/mysqlclient.20.dylib
试过
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
没有帮助。
请有人帮帮我。我真的被困住了。