View Full Version : MySql Driver not loaded
eekhoorn12
6th June 2007, 16:39
Hey all
I have a problem with mysql connection. When i try to connect to a mysql database i get the error "driver not loaded".
I use the following code:
#include <QApplication>
#include <QLabel>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("***********");
db.setPort(3306);
db.setDatabaseName("wachtrij");
db.setUserName("root");
db.setPassword("");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel;
if(createConnection() != false)
{
label->setText("Database connected");
}
else
{
label->setText("Database failed to connect");
}
label->show();
return app.exec();
}
I had a problem with compiling the code but that is solved.
I followed these instructions: http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW
and when i want to compile i ad QT += sql to the .pro file
I've searched trough this forum and other forums but couldn't find the solution.
I am using Qt 4.3 and mingw on windows xp
I hope you can help me.
eekhoorn12
8th June 2007, 01:32
I tried solving it by importing the plugin i did that the following way:
Configured with the following code:
configure -release -plugin-sql-mysql -I "C:\MySql\include" -L "C:\MySql\lib"
#include <QtPlugin>
Q_IMPORT_PLUGIN(qsqlmysql)
To the code
Made the .pro file with:
qmake -project "QT += sql" "QTPLUGIN += qsqlmysql"
And the when i run make i get the following error:
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `C:/Qt/4.3.0/Projects/hello'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o "release\hello.exe" tmp\obj\re
lease_shared\hello.o -L"c:\Qt\4.3.0\lib" -L"c:\Qt\4.3.0\lib" -lmingw32 -lqtmain
-lQtSql4 -lQtGui4 -lQtCore4 -LC:/Qt/4.3.0/plugins/sqldrivers/ -lqsqlmysql4 -LC:
\MySql\lib
tmp\obj\release_shared\hello.o(.text+0x859):hello. cpp: undefined reference to `q
t_plugin_instance_qsqlmysql()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\hello.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.3.0/Projects/hello'
mingw32-make: *** [release] Error 2
jacek
8th June 2007, 22:03
And the when i run make i get the following error:
You need static plugins to make it work that way.
Does sqlbrowser demo see the QMYSQL driver? Check with Dependency Walker (http://www.dependencywalker.com) whether the plugin can find MySQL DLLs (if not you will have to copy them to the same directory where your executable is).
eekhoorn12
10th June 2007, 16:39
I just reinstalled Mysql and Qt
Mysql to c:\mysql and qt to the default directory
After that i followed again the instructions from http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW
After that i configured Qt with the command
configure -static -plugin-sql-mysql -I "C:\MySql\include" -L "C:\MySql\lib"
When that was done i tried the sqldriver demo but it only showed QSQLITE and QODBC
Then i tried -shared -plugin-sql-mysql -I "C:\MySql\include" -L "C:\MySql\lib"
I got the same results.
I used dependency walker to check qsqlmysql4.dll from C:\Qt\4.3.0\plugins\sqldrivers and he got find al the dependency's except MPR.DLL
jacek
11th June 2007, 01:14
You might try clearing the plugin cache (http://doc.trolltech.com/4.2/plugins-howto.html#the-plugin-cache) --- maybe there's some stale data in it.
eekhoorn12
11th June 2007, 19:42
I cleared the plugin cache and then did the same thing as my previous post and still i get the same results.
jacek
11th June 2007, 20:35
I cleared the plugin cache and then did the same thing as my previous post and still i get the same results.
Copy libmysql.dll to %QTDIR%\demos\sqlbrowser\release, start the Qt Command Prompt (there's a link in Start menu) and invoke:
cd demos\sqlbrowser\release
sqlbrowser.exe
Can you see QMYSQL plugin in the "Driver" combo box?
eekhoorn12
11th June 2007, 21:28
No still just qsqlite and qodbc
Xerion
13th June 2007, 15:03
try building it static first:
-qt-sql-mysql -I"C:\mysql\include"
and make sure the libmysql.a is present in "C:\Qt\4.3\lib"
if you get compiler errors you can't resolve please post :)
eekhoorn12
14th June 2007, 00:32
Ok i removed all the programs again. Cleaned my register. Reinstalled Mysql and Qt.
After that i followed the following instructions: http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW
When i finished that i configured the program with
configure -qt-sql-mysql -I "C:\mysql\include"
I watched it pass by al de .pro files and noticed that it didn't make the mysql.pro file.
Reading C:/Qt/4.3.0/src/plugins/imageformats/tiff/tiff.pro
Reading C:/Qt/4.3.0/src/plugins/sqldrivers/sqldrivers.pro
Reading C:/Qt/4.3.0/src/plugins/sqldrivers/sqlite/sqlite.pro
Reading C:/Qt/4.3.0/src/plugins/iconengines/iconengines.pro
Also i didn't place a libmysql.a in the C:\Qt\4.3.0\lib folder but a liblibmysql.a
I tried de sqlbrowser demo and it didn't show mysql and i tried an example script and when i ran it i got the error message driver not loaded
I hope i did everything correct.
bongobonga
14th June 2007, 22:38
I have had the same problem and I have found a solution.
with mysql-5.0.41 I was able to compile the plugin for qt, but it just wasn't being loaded. I reverted back to an older version of mysql, in my case, 5.0.27 and everything worked fine.
This may or may not be the problem that you are having, but it is worth a try.
eekhoorn12
15th June 2007, 14:56
I have had the same problem and I have found a solution.
with mysql-5.0.41 I was able to compile the plugin for qt, but it just wasn't being loaded. I reverted back to an older version of mysql, in my case, 5.0.27 and everything worked fine.
This may or may not be the problem that you are having, but it is worth a try.
And how did you configure evrything?
Xerion
16th June 2007, 14:50
Maybe 2 other things you should check( if you haven't done for so far):
After you configured Qt you get a report which contains the configuration, make sure mysql is yes (or plugin).
Make sure your .pro file contains the line QT += sql
eekhoorn12
18th June 2007, 14:57
If you mean with the report the info get after you verify you want to configure qt the yes it always says that mysql: yes or mysqll: plugin
And when i compile a project i always follow the same three steps.
First: qmake -project "QT += sql"
Second: qmake projectname.pro
Third: make
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.