[solved] Driver not loaded QMYSQL
-
Hi all,
I'm getting crazy with QMYSQL :(. I want to connet to a mysql server through this code (for testing the connection only). Qt version is 5.2.1, while OS is Ubuntu 13.10.
@
#include <QCoreApplication>#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Started";
qDebug() << "library path " << a.libraryPaths();QSqlDatabase db; db.addDatabase("QMYSQL"); qDebug() << db.drivers(); qDebug() << "available = " << db.isDriverAvailable("QMYSQL"); qDebug() << "db error=" << db.lastError().databaseText(); qDebug() << "driver error=" << db.lastError().driverText(); db.setHostName("127.0.0.1"); db.setPort(3306); db.setUserName("root"); db.setPassword("mysql"); db.setDatabaseName("test"); bool done = db.open(); qDebug() << "done=" << done; if (! done) { qDebug() << "Failed to open database"; qDebug() << " - db error=" << db.lastError().databaseText(); qDebug() << " - driver error=" << db.lastError().driverText(); } qDebug() << "Terminating"; return a.exec();
}
@I get the following output:
Started
library path ("/home/fabio/Qt/5.2.1/gcc/plugins", "/home/fabio/Tests/Qt/build-TestDatabase-Desktop_Qt_5_2_1_GCC_32bit-Debug")
("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
available = true
db error= "Driver not loaded"
driver error= "Driver not loaded"
done= false
Failed to open database- db error= "Driver not loaded"
- driver error= "Driver not loaded"
Terminating
As you can see, driver is not loaded, even if all libs are at the correct places and dependencies are satisfied.
This is the past of the plugin dependencies
fabio@ubuntu:~$ ldd /home/fabio/Qt/5.2.1/gcc/plugins/sqldrivers/libqsqlmysql.so
linux-gate.so.1 => (0xb77de000)
libmysqlclient.so.18 => /usr/lib/i386-linux-gnu/libmysqlclient.so.18 (0xb7492000)
libQt5Sql.so.5 => /home/fabio/Qt/5.2.1/gcc/lib/libQt5Sql.so.5 (0xb7453000)
libQt5Core.so.5 => /home/fabio/Qt/5.2.1/gcc/lib/libQt5Core.so.5 (0xb6f89000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb6ea0000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6cec000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb6cd2000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb6ccd000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb6cb1000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6c6e000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb6c51000)
libicui18n.so.51 => /home/fabio/Qt/5.2.1/gcc/lib/libicui18n.so.51 (0xb6a2f000)
libicuuc.so.51 => /home/fabio/Qt/5.2.1/gcc/lib/libicuuc.so.51 (0xb68b6000)
libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 (0xb68b2000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb68a9000)
libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb67a5000)
/lib/ld-linux.so.2 (0xb77df000)
libicudata.so.51 => /home/fabio/Qt/5.2.1/gcc/lib/libicudata.so.51 (0xb525c000)
libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb521a000)and, in the turn, the pasting of libmysqlclient which the plugin depends on:
fabio@ubuntu:~$ ldd /usr/lib/i386-linux-gnu/libmysqlclient.so.18
linux-gate.so.1 => (0xb773a000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb73e6000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb73e1000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb73c5000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7382000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7365000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb71b1000)
/lib/ld-linux.so.2 (0xb773b000)To be more precise, I have built the plugin directly from source code (5.2.1) and the database mentioned in the code really exists on 127.0.0.1.
I also tried with QMYSQL3 (same result).
I really don't know what else to check.
Please help meThanks in advance
Fabio -
Solved,
addDatabase is a static function and then correct way to create an instance of database is the following:
@
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
@Sorry for the wasted time.
Fabio