Qt串連MySQL出現QSqlDatabase: QMYSQL driver not loaded

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.