iMAC上的Qt5.11.2,QSqlDatabase和MariaDB

时间:2018-10-04 14:36:05

标签: c++ database qt mariadb

我正在尝试连接到iMAC上的MariaDB。我知道数据库名称,要连接的用户名和密码正确。

我已经安装了Qt5.11.2,并且正在尝试以下操作:

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("Simons-iMac.local");
db.setDatabaseName("timekpr");
db.setUserName("timekpr");
db.setPassword("timekpr");
bool ok = db.open();

我在终端中ping了主机名,并且看到返回的IP地址。

当我进入open方法时,它返回false。我还能做些什么来获取有关为什么失败的更多信息?

iMAC运行的是iOS Mojave版本10.14

[编辑]当我使用调试器运行此程序时,在“应用程序输出”窗格中看到:

    2018-10-04 15:46:27.868976+0100 SimonQtWidgets[21670:626041] [default] Unable to load Info.plist exceptions (eGPUOverrides)
    2018-10-04 15:46:30.472706+0100 SimonQtWidgets[21670:625982] QSqlDatabase: QMYSQL driver not loaded
    2018-10-04 15:46:30.472764+0100 SimonQtWidgets[21670:625982] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    2018-10-04 15:46:34.975324+0100 SimonQtWidgets[21670:625982] QSqlError("", "Driver not loaded", "Driver not loaded")

根据第二行QMYSQL,我不知道发生了什么。但是报告的错误是驱动程序未加载??

如果有帮助:

Hardware Overview:

  Model Name:            iMac
  Model Identifier:      iMac17,1
  Processor Name:        Intel Core i7
  Processor Speed:       4 GHz
  Number of Processors:  1
  Total Number of Cores: 4
  L2 Cache (per Core):   256 KB
  L3 Cache:              8 MB
  Memory:                16 GB
  Boot ROM Version:      IM171.0157.B00
  SMC Version (system):  2.34f2

[另一个编辑]将QT_DEBUG_PLUGINS = 1添加到运行时环境后,我现在在应用程序输出中看到:

    2018-10-10 10:30:42.060973+0100 SimonQtWidgets[2001:286805] Got keys from plugin meta data ("QPSQL7", "QPSQL")
    2018-10-10 10:30:42.060985+0100 SimonQtWidgets[2001:286805] QFactoryLoader::QFactoryLoader() checking directory path "/Users/simonplatten/build-SimonQtWidgets-Desktop_Qt_5_11_2_clang_64bit-Debug/SimonQtWidgets.app/Contents/MacOS/sqldrivers" ...
    2018-10-10 10:30:42.063252+0100 SimonQtWidgets[2001:286805] Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
      Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
      Reason: image not found)
    2018-10-10 10:30:42.063276+0100 SimonQtWidgets[2001:286805] QLibraryPrivate::loadPlugin failed on "/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib" : "Cannot load library /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib: (dlopen(/Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib, 133): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib\n  Referenced from: /Users/simonplatten/Qt/5.11.2/clang_64/plugins/sqldrivers/libqsqlmysql.dylib\n  Reason: image not found)"
    2018-10-10 10:30:42.063293+0100 SimonQtWidgets[2001:286805] QSqlDatabase: QMYSQL driver not loaded
    2018-10-10 10:30:42.063465+0100 SimonQtWidgets[2001:286805] QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

似乎Qt期望mysql位于:

    /usr/local/mysql/

我没有安装,我使用以下方法搜索了mysql:

    find / -name mysql

发现:

    /usr/local/bin/mysql

也:

    /usr/local/Cellar/mariadb/10.1.17/bin/mysql
    /usr/local/Cellar/mariadb/10.1.17/include/mysql
    /usr/local/Cellar/mariadb/10.1.17/share/mysql
    /usr/local/Cellar/mariadb/10.2.6/bin/mysql
    /usr/local/Cellar/mariadb/10.2.6/include/mysql
    /usr/local/Cellar/mariadb/10.2.6/include/mysql/mysql
    /usr/local/Cellar/mariadb/10.2.6/.bottle/etc/init.d/mysql
    /usr/local/Cellar/mariadb/10.2.6/.bottle/etc/logrotate.d/mysql
    /usr/local/Cellar/mariadb/10.2.6/share/mysql

我也在分享中发现了这一点

    lrwxr-xr-x    1 simonplatten  admin     36 10 Jun  2017 mysql -> ../Cellar/mariadb/10.2.6/share/mysql

反正Qt在哪里寻找mysql吗?

1 个答案:

答案 0 :(得分:0)

已修复,方法如下:

从/ usr / local手动创建所需的文件夹结构:

0001_1234__abcd_defg_U_2018.08.24-14.50.23.TIF

创建指向所需库的符号链接:

    sudo mkdir mysql
    cd mysql
    sudo mkdir lib
    cd lib

然后这突出显示了使用域名进行连接的另一个问题,我使用本地主机解决了这个问题。