mysql - Qt 5.5 缺少 MYSQL 驱动程序

标签 mysql qt qt-creator

今天我开始使用 Qt 5.5,我的第一个项目是从 MYSQL 数据库中获取 GPS 相关数据并发送到另一台服务器。问题是我与 libqmysql.so 驱动程序文件有链接问题。我研究了如何解决问题,到目前为止我执行了以下步骤:

  • 我将所有文件(libqmysql.so 和其他驱动程序)复制到 /usr/lib/i386-linux-gnu/qt5/plugins/sqldrivers/home/magyarg/Qt5.5.1/5.5/gcc/plugins/sqldrivers
  • 我运行了 ldd libqmysql.so 来检查需要哪些依赖项;我得到以下结果:

enter image description here 根据这个结果,我安装了libssllibmysqlclient18

问题:

在这些步骤之后,Qt Creator 仍然向我抛出错误:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

环境:

  • Ubuntu Linux 15.04(x86)
  • Qt5.5

对应代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QtSql>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("127.0.0.1");
    db.setDatabaseName("ugyfelhivo");
    db.setUserName("root");
    db.setPassword("pass");
    bool ok = db.open();
    if (ok == true) {
        QLabel label;
        label.setText("Macska");
    }
}

最佳答案

通常此解决方案可以加载 QMYSQL:

cd /usr/lib/i386-linux-gnu/
sudo ln -s libmysqlclient_r.so.18 libmysqlclient_r.so.16

关于mysql - Qt 5.5 缺少 MYSQL 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34238251/

相关文章:

windows - 无法在 Qt Creator 中检索调试输出

php - 在 mysql 表中插入一行。它不起作用?

mysql - 将查询结果(列)插入 mysql 中的现有表中

php - 无法插入 SQL 表或显示全部来自

xcode - 如何使用 ‘xcode-select’设置事件的开发人员目录以进行Qt安装?

qt - 忽略 OSG 内 Qt 上的键盘按键

php - LIKE MYSQL 只得到 1 个结果

c++ - 我使用 Qt 的多线程应用程序出了什么问题(错误 SIGSEGV)

c++ - 模块 [] 未安装——为 QML 注册自定义 C++ 包装器

c++ - cmake 将子目录链接在一起