执行以下代码时,出现未加载Mysql驱动程序的错误:
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setDatabaseName("test");
db.setUserName("test");
db.setPassword("test");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
} else
qDebug() << "OPEN";
在我的.pro文件中,我用
添加了它QT += core gui sql
我使用的是Ubuntu 15.10并已安装 libqt5sql5 MySQL的 libqt4-SQL MySQL的
当我找到它时
locate libqsql
/usr/lib/i386-linux-gnu/qt4/plugins/sqldrivers/libqsqlmysql.so
/usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlite.so
/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so
同样在运行ldd命令时,可以找到所有依赖项:
ldd libqsqlite.so
linux-vdso.so.1 => (0x00007fff631e6000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f831f6d3000)
libQt5Sql.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5 (0x00007f831f691000)
libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f831f1d4000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f831ee52000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f831ea88000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f831e869000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f831e665000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f831e44b000)
libicui18n.so.55 => /usr/lib/x86_64-linux-gnu/libicui18n.so.55 (0x00007f831dfe7000)
libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f831dc53000)
libpcre16.so.3 => /usr/lib/x86_64-linux-gnu/libpcre16.so.3 (0x00007f831d9f0000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f831d6e0000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f831d4d8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f831d1d0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f831cfb8000)
/lib64/ld-linux-x86-64.so.2 (0x0000557933e71000)
libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f831b501000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f831b293000)
执行代码时,我得到输出:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
我还需要做点什么吗?