qt5.1.1没有加载mysql ubuntu QMYSQL驱动程序。

时间:2022-01-12 02:28:36

I'm trying to access mysql using Qt5.1.1 but i am getting the error the error below. I also searched a lot on google but unable to fix it.Please suggest me a solution so that i am able to resolve this error.

我尝试使用Qt5.1.1访问mysql,但是我得到了下面的错误。我也在谷歌上搜索了很多,但无法修复。请给我一个解决方案,这样我就能解决这个错误。

error:

错误:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3
QSqlError(-1, “ driver not loaded”, “ driver not loaded”)

code:

代码:

#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QtSql>
#include <QSqlDriver>
#include <qsqldatabase.h>
#include <QSqlError>
#include <QPluginLoader>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QSqlDatabase db= QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("NNF");
    db.setUserName("root");
    db.setPassword("root123");
    if( !db.open() )
    {
        qDebug() << db.lastError();
        qFatal( "Failed to connect." );
    }

    qDebug( "Connected!" );
    return a.exec();
}

2 个解决方案

#1


5  

If you are Ubuntu linux OS, you can install library:

如果你是Ubuntu linux操作系统,你可以安装库:

mic@ubt: ~$ apt-cache search libqt4-sql-mysql
libqt4-sql-mysql - Qt 4 MySQL database driver

mic@ubt: ~$ sudo apt-get install libqt4-sql-mysql 

#2


8  

Well, for Qt5 you need install MySQL, using the next command on the terminal, you resolve the problem:

对于Qt5,你需要安装MySQL,在终端上使用下一个命令,你解决问题:

sudo apt-get install libqt5sql5-mysql

#1


5  

If you are Ubuntu linux OS, you can install library:

如果你是Ubuntu linux操作系统,你可以安装库:

mic@ubt: ~$ apt-cache search libqt4-sql-mysql
libqt4-sql-mysql - Qt 4 MySQL database driver

mic@ubt: ~$ sudo apt-get install libqt4-sql-mysql 

#2


8  

Well, for Qt5 you need install MySQL, using the next command on the terminal, you resolve the problem:

对于Qt5,你需要安装MySQL,在终端上使用下一个命令,你解决问题:

sudo apt-get install libqt5sql5-mysql