Create MySQL driver for Qt on Windows

As you might have seen I'm working on the E-Sheet project of the Royal Belgian Ice Hockey Federation (RBIHF). This project is created with Qt on a Windows system and requires a connection to a MySQL database. Since Qt doesn't deliver the MySQL driver by default, I had to created it myself. You can recognize the problem from the following error: Driver not loaded.

I checked out several tutorials but they were either unsuccessful or extremely slow or even both. The main reason they were unsuccessful is that they aren't compatible with the new Qt versions (4.7.x and up). I listed a few of them below:

  • Qt Documentation
    This one should work, but will take a lot of time, since you have to compile Qt. Another problem was that while configuring Qt the following error occurred: Perl not found in environment - cannot run syncqt. A solution for this error can be found here.
  • Christopher.rasch-olsen.no
  • Berenger.eu

After searching a while I found this solution. It works and it's fast. This is what you should do:

  1. Download the needed software/source:
    • Qt SDK (if not installed yet)
    • MySQL Community Server (E.g. mysql-5.5.20-win32.msi) Make sure it is the 32-bit version, because the 64 bit version isn't supported yet.
      Update: As a few people mentioned in the comments, download a version that only contains the 32-bit version else you might encounter problems.
  2. Now there are three possibilities.
    • Qt SDK and Qt Sources are already installed. Continue to Step 3.
    • Qt SDK is installed but Qt Sources isn't.
      • Open Maintain Qt SDK this can be found at Start > All Programs > Qt SDK > Maintain Qt SDK
      • Select the Qt Sources you want to install and follow the wizard.
      • Continue with Step 3.
    • Qt SDK and Qt Sources aren't installed.
      • Install Qt SDK and don't forget to install the Qt Sources as well. Otherwise go to the step above.
      • Once everything is installed continue with Step 3.

    I installed the Qt SDK in C:\QtSDK and this path will be used below, so remember it. You should also remember the version of the Qt Sources, here it's 4.7.3

  3. Install MySQL. You only need to install the Client C API Library the other components are optional for this tutorial. I installed it in C:\Program Files (x86)\MySQL\MySQL Server 5.5. Since the path contains spaces, you should use C:\PROGRA~2\MySQL\MYSQLS~1.5, else it won't work. 1
  4. Open the Qt Command Prompt.
    Start > All Programs > Qt SDK > Desktop > Qt 4.7.3 for Desktop (MinGW)
  5. Run the following commands (change them according to your environment):
    1. set mysql=C:\\PROGRA~2\\MySQL\\MYSQLS~1.5
    2. cd C:\QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql\
    3. qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro
    4. mingw32-make
    5. qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"
    6. mingw32-make
  6. Copy the following files to C:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\sqldrivers
    • libqsqlmysqld4.a and qsqlmysqld4.dll from C:\QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql\debug
    • libqsqlmysql4.a and qsqlmysql4.dll from C:\QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql\release
  7. Copy libmysql.dll from %mysql%\lib to C:\Windows

That's all, but don't forget to add QT += sql to your project file, else it won't work. To check which drivers are available run this program. You can also download the code as a Qt project in the attachments.

  1. #include <QtCore/QCoreApplication>
  2. #include <QtSQL>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     QCoreApplication a(argc, argv);
  7.     qDebug() << QSqlDatabase::drivers();
  8.     return a.exec();
  9. }

1 Note: For 32-bit systems the install path of MySQL will be C:\Program Files\MySQL\MySQL Server 5.5 and the path without spaces will be C:\PROGRA~1\MySQL\MYSQLS~1.5. To determine a custom path without spaces, use the dir /x command.

Attachments: 

Comments

when doing step 3 ie qmake command i get following errors:
WARNING (internal):1: Unescaped backslashes are deprecated.
Why is this error occuring. PLEASE REPLY...

First of all it's a warning not an error, which is a good thing. The warning informs us that we should escape the backslashes, because the unescaped version will be unsupported in the future. To fix this you should replace 1 and 3 of the fifth step by the following:

  1. set mysql=C:\\PROGRA~2\\MySQL\\MYSQLS~1.5
  2. cd C:\QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql\
  3. qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro

Note that 2 didn't change.

I hope this answers your question and solves the problem.

Works perfect for me with Qt 4.8.1, i used :

set mysql=C:\\MySQL
cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql\
qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro
mingw32-make
qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"
mingw32-make

for the compilation.
Thank you very much, it was really helpful.

I am very appreciating this blog, before solved the problem, it has cost my one afternoon.

i did all the stapes
compilation
cpying the two .dll and the others .a , adding libmysql.dll
it dosen't work
im using version 4.8.2 and mysql 5.5.24-win 32

Do you get any errors during the compilation? Or any other indication of where it went wrong?

Also make sure you didn't forget to change one of the 4.7.3's in one of the commands and that the path to your MySQL files is correct. ;)

I enter this code but not working????
pls help me!

set mysql=K:\\Program Files\\MySQL\\MySQL Server 5.5
cd k:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql\
qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro
mingw32-make
qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"
mingw32-make

windows 7 32bit and installed in Drive K:\

Give me this error:
k:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=K:\\Pr
ogram Files\\MySQL\\MySQL Server 5.5\\include" "LIBS+=K:\\Program Files\\MySQL\\
MySQL Server 5.5\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"

k:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `k:/QtSDK/QtSources/4.8.1/src/plugins/sqldri
vers/mysql'
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN
-DQT_SQL_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAV
E_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"k:\QtSDK\Desktop\Qt\4.8.1\mingw\i
nclude\QtCore" -I"k:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtSql" -I"k:\QtSDK\Des
ktop\Qt\4.8.1\mingw\include" -I"k:\Program" -I"Files\MySQL\MySQL" -I"Server" -I"
5.5\include" -I"k:\QtSDK\Desktop\Qt\4.8.1\mingw\include\ActiveQt" -I"release" -I
"k:\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\default" -o release\main.o main.cpp
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or d
irectory
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:108: error: expected ')' before '*' toke
n
mingw32-make[1]: *** [release/main.o] Error 1
mingw32-make[1]: Leaving directory `k:/QtSDK/QtSources/4.8.1/src/plugins/sqldriv
ers/mysql'
mingw32-make: *** [release] Error 2

The problem is that your MySQL path contains spaces. You can determine the space-free path by using the DIR /X command in the command prompt.

But in this case the following should work: change set mysql=K:\\Program Files\\MySQL\\MySQL Server 5.5 to set mysql=K:\\PROGRA~1\\MySQL\\MYSQLS~1.5

I have used your path without space and double backlash but this error was still there

k:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=K:\\Pr
ogram Files\\MySQL\\MySQL Server 5.5\\include" "LIBS+=K:\\Program Files\\MySQL\\
MySQL Server 5.5\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"

k:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `k:/QtSDK/QtSources/4.8.1/src/plugins/sqldri
vers/mysql'
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_NO_DEBUG -DQT_PLUGIN
-DQT_SQL_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAV
E_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"k:\QtSDK\Desktop\Qt\4.8.1\mingw\i
nclude\QtCore" -I"k:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtSql" -I"k:\QtSDK\Des
ktop\Qt\4.8.1\mingw\include" -I"k:\Program" -I"Files\MySQL\MySQL" -I"Server" -I"
5.5\include" -I"k:\QtSDK\Desktop\Qt\4.8.1\mingw\include\ActiveQt" -I"release" -I
"k:\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\default" -o release\main.o main.cpp
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or d
irectory
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:108: error: expected ')' before '*' toke
n
mingw32-make[1]: *** [release/main.o] Error 1
mingw32-make[1]: Leaving directory `k:/QtSDK/QtSources/4.8.1/src/plugins/sqldriv
ers/mysql'
mingw32-make: *** [release] Error 2

Please help me, this is for my last assignment in my campus..

qmake "INCLUDEPATH+=K:\\Program Files\\MySQL\\MySQL Server 5.5\\include" "LIBS+=K:\\Program Files\\MySQL\\
MySQL Server 5.5\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"

Nope, you missed somes spaces, parts that contain spaces are marked in bold. Take a look at step 3 and the note at the bottom of the article.
Hope this helps!

evry thing is all right (the copilation were fine)
but it dosen't want to work
qsqlmysql4.dll and qsqlmusqld4.dll are in qt\4.8.1\plugins\sqldrivers the two other .a too eihter mysql.dll is in 4.8.1\bin

First of all, I'm going to assume you mean libmysql.dll when you say mysql.dll, correct me if I'm wrong. :) If this is the case the file shouldn't be copied into the qt\4.8.1\bin folder but into C:\Windows. The original file can be found in the %mysql%\lib folder.

Also don't forget to add QT += sql to your projectfile. Hope this helps!

ye ur right i mean libmysql.ddl when i said mysql.dll
and i copyed this file into c:\windows, c:\qt\4.8.2\bin and i affected in "PATH" variable
no positive result
can i do the work with QtSDK v1.2 cause im working with QTSDK1.1...TANKS MAN

I'm also using QtSDK 1.1.* so normally it should work. What did you change in the PATH variable? Since I didn't have to change anything in the PATH...

i added c:\mysql\lib folder to PATH vriable
this is my Skype "ayoubooooo"
i spent two weeks to resolve this problem and i can't
i ask you to fixe a "rondez vous" in skype plz
and thanx in advance

Thanks a lot. I've spent a lot of time trying to make QT4 working with MySQL, but your with your instruction I finally did it for 2 min :).

i too compiled the drivers in my windows 7 but i am unable to use the same in other system, why is it so??

is there any way to solve this problem???

If you want to build the program on the other system just compile the driver on that system. I don't know why you can't use it exactly, but I guess it's because the paths of Qt, MinGW and MySQL are different on the machine.

If you want to deploy (run) the program on the other system, copy the dll's into the same folder as the executable. The MySQL driver, and other sql-drivers, have to be placed in a subfolder called "sqldrivers". An example of the application folder structure:

  • sqldrivers
    • qsqlmysql4.dll
  • app.exe
  • libmysql.dll
  • QtCore4.dll
  • ...

I hope this solves your problem.

error: mysql.h: No such file or d
irectory
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:108: error: expected ')' before '*' toke
n

this is how the command prompt looks like

C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=%mysql
%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro

C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql>mingw32-make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/QtSDK/QtSources/4.8.1/src/plugins/sqldri
vers/mysql'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -
DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_H
AVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore"
-I"c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtSql" -I"c:\QtSDK\Desktop\Qt\4.8.1\m
ingw\include" -I"c:\MySQL\MYSQLS~1.5\include" -I"c:\QtSDK\Desktop\Qt\4.8.1\mingw
\include\ActiveQt" -I"debug" -I"c:\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\default"
-o debug\main.o main.cpp
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or d
irectory
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:108: error: expected ')' before '*' toke
n
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make[1]: Leaving directory `C:/QtSDK/QtSources/4.8.1/src/plugins/sqldriv
ers/mysql'
mingw32-make: *** [debug] Error 2

This is an indicator of an incorrect path to MySQL. Make sure the path is correct, you can do this by copying the path you're using for the %mysql% variable and paste it into the address bar of Windows Explorer. If you get an error the path is incorrect, else you will go to the folder where MySQL is installed.

i'm sorry but i have the same problem,it tells me that can't find the mysql.h .but i am sure the MySQL path is correct and without spaces(for me ,i change it to "C:\MySQL" ) and this is my errors:
Setting up environment for Qt usage...

C:\windows\system32>cd c:\qtsdk\qtsources\4.7.4\src\plugins\sqldrivers\mysql\

c:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\mysql>qmake "INCLUDE+=C:\MySQL\i
nclude" "LIBS+=C:\MySQL\lib\libmysql.lib" -o Makefile mysql.pro
WARNING: (internal):1: Unescaped backslashes are deprecated.
WARNING: (internal):1: Unescaped backslashes are deprecated.
WARNING: (internal):1: Unescaped backslashes are deprecated.

c:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\mysql>mingw32-make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `c:/QtSDK/QtSources/4.7.4/src/plugins/sqldri
vers/mysql'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -
DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_H
AVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtCore"
-I"c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtSql" -I"c:\QtSDK\Desktop\Qt\4.7.4\m
ingw\include" -I"c:\QtSDK\Desktop\Qt\4.7.4\mingw\include\ActiveQt" -I"debug" -I"
c:\QtSDK\Desktop\Qt\4.7.4\mingw\mkspecs\default" -o debug\main.o main.cpp
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:52:19: error: mysql.h: No such file or d
irectory
In file included from main.cpp:44:
../../../sql/drivers/mysql/qsql_mysql.h:108: error: expected ')' before '*' toke
n
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make[1]: Leaving directory `c:/QtSDK/QtSources/4.7.4/src/plugins/sqldriv
ers/mysql'
mingw32-make: *** [debug] Error 2

this is my mail: *********@gmail.com and pls help me,it takes me about two weeks and i'm going insane.

i input "INCLUDE+=....." where it should be "INCLUDEPATH+=....." ,now it is good and i connect to mysql successfully,thanks very much!

C:\>set mysql=C:\MySQL\MySQLServer5.1

C:\>qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\opt\\libmysql.lib
" -o Makefile mysql.pro
Cannot find file: mysql.pro.

hey i tried cancelling the spaces by changing the folder name of MYSQLServer, it worked for me...

I am on the 7th step,
Copy libmysql.dll from C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib to C:\Windows

but in my pc, dll is not there in lib/opt folder, where is the dll?

Since you used C:\MySQL\MySQLServer5.1 for %mysql% the dll will be in that folder. I changed it in the post. ;)

When using this method, it worked perfectly when making the .ddl and .a files, however, Qt was still not working with the driver. My problem was that even with the line Qt += sql in my .pro file, the libraries weren't being included. I had to copy all of the lib files in C:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\sqldrivers to C:\QtSDK\Desktop\Qt\4.8.1\mingw\lib. I also had to include these lines in my .pro file:

"INCLUDEPATH+=C:\PROGRA~1\MySQL\MYSQLS~1.5\include"
"LIBS+=C:\PROGRA~1\MySQL\MYSQLS~1.5\lib\libmysql.lib"

While some people may find that this is uneccessary, if you are having problems, this might be the solution. Hope this is useful.

There's no words to say how grateful I am !
I wasted something like 2 entire days to try compiling this @#*?%! mysql driver !

Then I found your "tutorial", I followed the steps, and it worked immediately !
Just thank you :)

I tried the above tutorial and it worked but QMYSQL driver was not included in the driver list only QSQLITE and QODBC, i really need to QMYSQL driver. thanks

Are you sure you didn't forget step 6? Also make sure you changed the version (4.7.3) to the version you are using. ;)

I have follow all the step as you mention. but it could'nt working. I generated release and debug .a and .dll files and put it into your given path and download your project also but its not loading mysql driver.

That's very strange, the only explanation I can think of is that the files aren't placed in the correct folder...

mingw32-make does not want to work. Is there another way to use a 'make' commands?

Make sure you are using the Qt Command Prompt (Step 4). Another possibility is to look into Cygwin or build it using Visual Studio.

Even for me also everything was done successfully.But when I run th program it didnt list mysql

I am using the lateast Qt SDK 4.8.4. Its not listing MySQL driver.Please help

Qt commercial SDK is installed in path C:\QtCommercialSDK\Src\qt\484\src\plugins\sqldrivers.
In This path I copied all the four files.I dont find any Qtsoureces folder.Is it correct?

Normally if you completed step 2 the folder should be there... However it might be that in the commercial version the directory has a different name, but I doubt it.

Do you have multiple versions of Qt installed? If so, are you using (building with) the correct version in the project?

Hey! I'd like to thank you!
Your post is precise and it worked perfectly!
It is necessary to pay attention to details!
It worked with Qt 4.8.1, MySQL 5.5 (32 bit) on my Win 7 64 bit machine.
Thanks a lot!

Hi there,

thanks for your help works fine with Qt 4.7. I'm currently downloaded the new Qt 5.0 Open Source Version with MingW but i don't know how to compile the MySQL Drivers for the qt 5 environment. I can not find an QtSDK from 5.0. Qt 5.0 comes only with sqlite drivers :( Any idea how to fix this?

Best Regards
Marco

Hi Marco,

I already figured out how to compile it, but I haven't found the time to create a tutorial about it. Normally I should be able to find some time this week. Hang on, help is on the way! ;)

I just posted the tutorial for Qt5, you can find it here.

Hi, thanks so much for this tutorial!
You are the first one who wrote a tutorial for qt 5.0 :)

Best wishes
Marco

Dear Seppe Magiels,

i just created an Install Script which installs "Qt Creator 5.0.1" (if not already installed), installs the necessary MySql C-Library (Silent Installation, if not already installed), and also creates the Sources folder (If not already installed). After this process the Scripts compiles and copies the DLL Files in the necessary directories.

I will upload this Installation Files on my Server, and if you allow, i can post the URL over here?! Of cause the Code is included into the Zip File, so everyone can configure the Script how he needs.

Best Regards
Marco

Dear Marco,

That would be great. I will add it to the article as well, if you don't mind of course.

Thanks!

It didn't worke for me my mysql path is in C:\Program Files\MySQL\MySQL Server 5.6 and i change it to
set mysql c:\\PROGRA~1\\MySQL\\MYSQLS~1.6
and wrote these instruction:
cd C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql\

qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro
mingw32-make
show me error for example:
make[1]: ***[tmp/obj/debug_shared/main.o] Error 1
make[1]: leaving directory '/c/QtSDK/QtSources/4.8.1/src/plugins/sqldrivers/mysql'

and same error for this instructure:
qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro "CONFIG+=release"
mingw32-make

I haven't tried it with MySQL Server 5.6, so give it a try with version 5.5 normally that should work. Also make sure you use the 32-bit version of the MySQL server.

Hey Seppe,
Thanks very much for all your input on this. For me its turning out te be the last straw. I would very much appreciate some help: The problem is: my .a files are being created as expected in both folders, but the .dll's fail. I get big amount of lines like:

C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1377: undefined reference to `mysql_free_result@4'
debug/qsql_mysql.o: In function `ZNK12QMYSQLDriver6recordERK7QString':
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1430: undefined reference to `mysql_list_fields@12'
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1436: undefined reference to `mysql_fetch_field@4'
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1438: undefined reference to `mysql_free_result@4'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver16beginTransactionEv':
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1456: undefined reference to `mysql_query@8'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver17commitTransactionEv':
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1473: undefined reference to `mysql_query@8'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver19rollbackTransactionEv':
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1490: undefined reference to `mysql_query@8'
debug/qsql_mysql.o: In function `ZNK12QMYSQLDriver11formatValueERK9QSqlFieldb':
C:\Qt\4.8.4\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.c
pp:1516: undefined reference to `mysql_real_escape_string@16'
collect2: ld gaf exit-status 1 terug
mingw32-make[1]: *** [debug\qsqlmysqld4.dll] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.8.4/src/plugins/sqldrivers/mysql'
mingw32-make: *** [debug] Error 2

Any idea what the source of this error can be?
cheers,

Never mind, I got it working! For everyones informations: The errors had to do with it being a 64bit version that gtot installed. (for some reason, downloading the MySQL msi for BOTH 64 and 32, and choosing the architecture during install, still made it 64bit at some level. Even though I'm sure I choose 32bit.)After changing it to 32bit by doing a manual(zip archive) install for 32bit only, was I succesfull. Then all I had to add was
QT += sql
to the .pro file to get it working.
Still: thnx for doing a great service to the community with this blog.
Cheers

Glad you got it working and thanks for the update! ;)

Pages