Home > Database > Mysql Tutorial > Qt连接MySQL出现QSqlDatabase: QMYSQL driver not loaded

Qt连接MySQL出现QSqlDatabase: QMYSQL driver not loaded

WBOY
Release: 2016-06-07 15:40:50
Original
3200 people have browsed it

QSqlDatabase:QMYSQLdrivernotloaded QSqlDatabase:availabledrivers:QSQLITE 解决方法,先看下是否已经安装了libqsqlmysql.so [test1@localhost~]$locatelibqsqlmysql.so /var/cache/abrt-di/usr/lib/debug/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so.

QSqlDatabase: QMYSQL driver not loaded

QSqlDatabase: available drivers: QSQLITE

解决方法,先看下是否已经安装了libqsqlmysql.so

[test1@localhost ~]$ locate libqsqlmysql.so

/var/cache/abrt-di/usr/lib/debug/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so.debug

我的系统上还没有安装,下面安装 qt-mysql.i686。

[root@localhost test1]# yum install qt-mysql.i686

================================================================================

 Package           Arch          Version                 Repository        Size

================================================================================

Installing:

 qt-mysql          i686          1:4.7.4-7.fc14          updates           67 k

[root@localhost test1]# updatedb

[test1@localhost ~]$ locate libqsqlmysql.so

/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so

/var/cache/abrt-di/usr/lib/debug/usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so.debug

在程序里面调用

qDebug()QCoreApplication::libraryPaths ();

可以看到Qt 搜索库的路径。里面并没有/usr/lib/qt4/plugins/

这里有两种方式解决这个问题:

1、把libqsqlmysql.so所在的路径增加到库路径里面:

     QcoreApplication::addLibraryPath("/usr/lib/qt4/plugins/");

2、直接复制libqsqlmysql.so到Qt的搜索路径中。

[test1@localhost ~]$ cp /usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so QtSDK/Desktop/Qt/4.8.1/gcc/plugins/sqldrivers/    



http://doc.qt.nokia.com/4.7-snapshot/sql-driver.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template