PDA

View Full Version : Yet Another QMYSQL driver not loaded issue



Jits
8th September 2010, 13:50
Hi All

Running Red Hat Enterprise Linux Server release 5.4 (Tikanga) with Qt4.7.0 32-bit and downloaded and yum installed MySQL-embedded-community-5.1.50-1.rhel5.i386.rpm (wish to embed MySQL)

Followed all the directions as set out here (with some path changes and the necessary changes for the embedded lib):

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

This is what I have in ../../../src/plugins/sqldrivers/mysql




[root@localhost mysql]# ll
total 29204
-rwxr-xr-x 1 root root 29686009 Sep 8 13:01 libqsqlmysql.so
-rw-r--r-- 1 root root 2798 Jun 2 04:03 main.cpp
-rw-r--r-- 1 root root 10244 Sep 8 13:01 main.o
-rw-r--r-- 1 root root 8947 Sep 8 12:58 Makefile
-rw-r--r-- 1 root root 2641 Sep 8 13:01 moc_qsql_mysql.cpp
-rw-r--r-- 1 root root 5940 Sep 8 13:01 moc_qsql_mysql.o
-rw-r--r-- 1 root root 585 Jun 2 04:03 mysql.pro
-rw-r--r-- 1 root root 2412 Sep 8 13:01 qsql_mysql.moc
-rw-r--r-- 1 root root 79112 Sep 8 13:01 qsql_mysql.o
-rw-r--r-- 1 root root 204 Jun 2 04:03 README


and the following in ../../..//plugins/sqldrivers


[root@localhost sqldrivers]# ll
total 10960
-rwxr-xr-x 1 root root 424302 Jun 2 14:18 libqsqlite2.so
-rwxr-xr-x 1 root root 1601752 Jun 2 14:17 libqsqlite.so
-rwxr-xr-x 1 root root 8602384 Sep 8 13:01 libqsqlmysql.so
-rwxr-xr-x 1 root root 537311 Jun 2 14:18 libqsqlpsql.so


Running the following code (having included Qt += sql in the project file)


#include <QCoreApplication>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QStringList>
#include <QtDebug>

int main( int argc, char **argv )
{
QCoreApplication app( argc, argv );
//app.addLibraryPath("/opt/qtsdk-2010.04/qt/plugins/sqldrivers");
qDebug() << QSqlDatabase::drivers();
QSqlDatabase db( QSqlDatabase::addDatabase( "QMYSQL" ) );
qDebug() << db.lastError();
qDebug() << app.libraryPaths();
}

Produces the following


("QSQLITE")
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
QSqlError(-1, "Driver not loaded", "Driver not loaded")
("/opt/qtsdk-2010.04/qt/plugins")

As it is obvious that QMYSQL is still not loaded, I am at a loss as to what to do next. Have spent two days on the net already, looking for solutions.

It seems to me as if the library compiled correctly and that the include path is fine, yet Qt still doesn't pick up the plugin. What could I have missed?

Any help will be greatly appreciated.

tbscope
8th September 2010, 13:53
Why does the installed size differ?



-rwxr-xr-x 1 root root 29686009 Sep 8 13:01 libqsqlmysql.so
-rwxr-xr-x 1 root root 8602384 Sep 8 13:01 libqsqlmysql.so

Jits
9th September 2010, 06:23
Could it be because the debug info is stripped during "make install"? I removed, deleted, uninstalled and destroyed all the existing files, libs and directories and went through the whole procedure again, but still no luck. Everything exactly the same.

I can use SQLite, but when it comes to things like these I'm a bit of an irritation to myself, I really want to know WHY it doesn't work when everything says it should! :)

tbscope
9th September 2010, 06:55
I don't think make install strips the binary.

Another problem that might occure is a difference in either compiler or used libraries.
In other words, the Qt library might be compiled with a Microsoft compiler and you compile it with gcc for example.

Jits
9th September 2010, 07:56
I'm going to try and run configure and see if that produces better results than the manual install...Will also have a look into the compilers, but I believe it's all gcc.

Thanks for the input! Will report back here in a few hours (gmake takes aaaaages on my machine).

Bruce Eng
22nd October 2010, 15:54
This same thing happened to me. Finally after digging through forums I found something helpful: the QPluginLoader. This doesn't fix anything, but it does have an errorString that can help troubleshoot:

QPluginLoader *thePlugin = new QPluginLoader("C:/qt/2009.05/qt/plugins/sqldrivers/qsqlmysqld4.dll");
qDebug() << thePlugin->load();
qDebug() << thePlugin->isLoaded();
qDebug() << thePlugin->errorString();

In my case the error was "module not loaded" so I opened up qsqlmysqld4.dll with the Dependency Editor and it couldn't find libmysql.dll. If you remember this is the dll that comes with MySQL. The final fix was just copying this file (libmysql.dll, not qsqlmysql4.dll) to the folder with my executable in it. Now the QMySQL driver works and I will note that for what I am doing it is almost twice as fast as the QODBC driver.