views:

121

answers:

2

I have a QT application that requires the MySql driver. I have both a .pro file to compile the app with QtCreator and a .vcproj for Visual C++ 2008 Express. The code is identical and it compiles without a hitch, but the executable created by Visual C++ Express gives me the following output and refuses to load any driver/plugin:

QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers:

I used QCoreApplication to identify the location where the plugins are and it seems that both executables have the same path, so they should both see the plugins. One does, and the other doesn't.

The code is standard.

QSqlDatabase db; db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setPort(3306); db.setDatabaseName("dbase"); db.setUserName("user"); db.setPassword("pwd"); bool ok = db.open();

The same thing happens with the SqlBrowser sample that came with QT, so I don't think the code is the problem.

A: 

I faced this error before and couldn't get it to work until I realised plug-in wasn't built using the same configuration as my application (debug vs release, doh!).

JP
A: 

For anyone else who bumped into this problem I have to say this - it is much easier to use one of the packages containing QT pre-built binaries for Visual C++ than trying to build it yourself. And the Qt driver (the 4.3 version at least) is awfully hard to get to work (on some machines it works like a charm but on others it can't find the driver, using the same code and binaries), so you are much better off using a dedicated MySql library.

Tomis