This is meant to be a quick howto / tutorial on how to setup a build-enviroment for C++ / Qt with Qt Creator ( Trolltech / Nokias new Qt IDE) where you use Mingw to compile your applications and have a MySQL-plugin available.
Getting the required files
You will be needing three files to get started.
First get the latest GA-release of MySQL. Go to their download-section and find the “Windows MSI Installer” for your architecture (x86 or x64). Save the file to your desktop.
Then go to Trolltech / Nokias download-section to get the LGPL’ed Qt SDK. Save the file to your desktop.
Finally go to the Mingw download-section to get the Mingw Utilities. I downloaded version 0.3 (latest version as of this writing). Save the file mingw-utils-0.3.tar.gz to your desktop.
In addition to the three files mentioned above you might need WinRAR or a similar tool to unpack tar.gz-files.
Installing MySQL
I always start by installing MySQL. This is not a requirement and the order in which you install MySQL and Qt does not matter.
Start the MySQL-installer you have on your desktop. Choose the advanced install options. I usually remove the MySQL server instance from the install as I have several external database-servers I do tests against. No need to clutter the dev-box if you have it available other places.
What’s important here is that you choose to install “Development Components” and all sub-features. These are the ones that’ll enable Qt to know how to reach a given MySQL database.
Another important step here is to install directly to c:\mysql, not c:\Program Files\Mysql\MySQL Server\whatnot. Spaces in pathnames confuse certain of the items in the toolchain. If you do install somewhere with spaces in the path then you have to remember to always use the old style-pathnames: c:\Progra~1\etc .
Proceed with the install, and after completion verify that you have libmysql.dll under c:\mysql\bin, and that there is a directory c:\mysql\include with header-files (.h) in it.
Installing Qt SDK
Start the Qt SDK installer and choose to install it in c:\Qt\2009.01 or whatever path it propose, as long as it is a path without spaces in it. Choose to install all the components, including Mingw.
Installing Mingw Utilities
The Mingw Utilities is simply a collection of executables, plus a couple of dlls. Open the file you downloaded earlier with a suitable program like WinRAR and copy the _contents_ of the bin-directory into C:\Qt\2009.01\mingw\bin.
Fixing (?) QMake
It might just be me having this problem, but I had to rebuild QMake even before configure would run and not crash spewing something about not finding stuff in ‘c:\Progra~1\Trolltech..’. Anyway, it’s not exactly rocketscience. Locate the ‘Qt Command Prompt’ and start that. It will upon execution add a couple of locations to PATH so that you’ll have the tools you need easily available. From there you do the following.
C:\Qt\2009.01> cd qt\qmake
C:\Qt\2009.01\qt\qmake> mingw32-make clean
C:\Qt\2009.01\qt\qmake> mingw32-make
After that QMake should start looking for mkspecs and other candy in the appropriate locations.
Preparing Qt for building
The next thing you want to do is run configure with a handful of arguments. For the sake of simplicity I’ll just include the arguments you need to have Qt build with the MySQL-plugin.
Again, in the Qt Command Prompt:
C:\Qt\2009.01\qt> configure.exe -debug-and-release -plugin-sql-mysql
The above will create Makefiles and things for all the sub-projects in the Qt directory-tree. This might take a little while so you might want to have some knitting-needles or a book at hand.
See ‘configure.exe -help’ for more options.
Configuring the MySQL-plugin
The Qt Reference Documentation is one of the best pieces of documentation I’ve ever seen. It’s full of working examples of how to use the API Trolltech / Nokia provide and generally have a very high level of quality.
However when it comes to how to build Qt with certain plugins it can be a bit lacking. The documentation here states that you do the following to build the MySQL-plugin on Windows:
cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server\lib\opt\libmysql.lib" mysql.pro
nmake
That’s great, _if you use nmake_. Alot of us rely on Mingw to build our applications on Windows, and for us the above simply will not work. That is due to differences in object and lib-format between MSVC (which the mysql-dll’s are built with) and the GNU-toolchain. To solve this you have to do some magic on the dll and produce something that the GNU-toolchain can work with.
Proceed by doing this in the “Qt Command Prompt”:
C:\Qt\2009.01\qt> cd src\plugins\sqldrivers\mysql
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> set MYSQL_PATH=c:mysql
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> reimp -d %MYSQL_PATH%\lib\opt\libmysql.lib
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> dlltool -k --input-def LIBMYSQL.def --dllname libmysql.dll --output-lib libmysql.a
C:\Qt\2009.01\qt\src\plugins\sqldrivers\mysql> qmake "INCLUDEPATH+=%MYSQL_PATH%include" "LIBS+=-L. -lmysql" mysql.pro
Building Qt
When all of the above has been done all you have to do is start the Qt build process. Again in the “Qt Command Prompt”:
C:\Qt\2009.01\qt> mingw32-make sub-src
That’s it! You should now have qmysql*.dll in pluginssqldrivers. To use it just make sure that you have the path where you find libmysql.dll (usually C:\mysql\bin) as a part of the environment variable PATH.
Questions and comments are as always welcome.

This is great. I have really been struggling with building the MySQL driver plugin using MinGW. Can I build the plugin with nmake and then build my application with mingw32-make? Or do both my application and the plugin need to be built the same way?
Glad I could help!
As far as my understanding goes this is not possible. Are there any good reasons why you’d want to do that? Aside from producing smaller binaries, which are not as important today as it used to be back in the day, nmake does not give that much added value IMHO. Distribution / deployment of MingW-compiled binaries is also much less cumbersome than that of binaries produced with nmake (manifests and XML-hell anyone? :p ).
Anyway, I’m interested in more reasons to use nmake, since I have not found that many myself, except reducing hairloss while configuring Qt.
I am trying to follow your guide but in the command lines in this guide show no ‘/’ and ‘\’. Or at least on my webbrowsers (IE and google chrome). Could you re-type them in a comment.
ps: what i see is the following:
C:Qt2009.01> cd qtqmake
C:Qt2009.01qtqmake> mingw32-make clean
C:Qt2009.01qtqmake> mingw32-make
not that there are no \ or /
Thanks David for the “heads-up”.
It seems like this is caused by Wordpress’s way of parsing posts. It has now been corrected.
While we are on that page; please note that you have to use a bit of “common sense” as to where lines are separated / terminated. Some lines are very long and have been “broken” over several lines on the page here. If someone would enlighten me as to how one can write multi-line commands on Windows then I’ll update the post by properly formatting the examples.
Thanks Christopher for this wonderful tutorial. Thanks to your help at last I was able to get mysql driver compiled with mingw. I’ve been stuck on this for a week now, and now I can go on with my work.
Cheers!
Glad to be of service. It’s always nice that ones work is appreciated.
Hi Christopher,
Nice posting. Wish that I had found this site before I started getting Mysql working with QT. Question, though… I have done everything to:
qmake “INCLUDEPATH+=%MYSQL_PATH%include” “LIBS+=-L. -lmysql” mysql.pro
and so far, so good. However, whenever I do the qmake, I keep getting the error: Unable to find main.cpp.
Any ideas?
Its hard for me to know without any more detail that that. I would advise that you come to the Qt interest mailinglist and post some output. I’m sure there are several of us there who might be able to help you.
Good luck!
This could do with all the \ putting in the right places and the extra paths to the mysql includes
cd %QTDIR%\src\plugins\sqldrivers\mysql
set MYSQL_PATH=c:\mysql
C:\Qt\2009.03\mingw\bin\reimp -d %MYSQL_PATH%\lib\opt\libmysql.lib
C:\Qt\2009.03\mingw\bin\dlltool -k –input-def LIBMYSQL.def –dllname libmysql.dll –output-lib libmysql.a
qmake “INCLUDEPATH+=%MYSQL_PATH%\include” “LIBS+=-L. -lmysql” mysql.pro
Also i had to get reimp as it is an additional package for mingw
Hi Dave,
Thank you for the heads-up on missing /’s. I’ve had a few rounds with wordpress and /-substitution. It’s quite annoying. I hope I got the rest of them in now.
About reimp: in the start of the blogpost I wrote that I downloaded ‘MinGW Utilities’ (mingw-utils-0.3-src.tar.gz). In that file you will find reimp. Perhaps it was not clear enough. I guess it would be easy to think that you should use that link to download MinGW itself. I’ll try to find a better wording for that section.
Thanks for commenting.
reimp -d %MYSQL_PATH%\lib\opt\libmysql.lib didn’t work. ANy way around?
its says, reimp not recognised. I am in hurry. Please reply soon.
You need to have reimp in your PATH. RIght-click on ‘My Computer’ on your desktop, select ‘Properties’ and navigate to ‘Environment variables’. Add the path to reimp (the directory reimp resides in). Save and exit. If you open a new command prompt then the PATH-change should be active.
Now I have another big problem. I did use the reimp by giving absolute path, but now with qt-creator I can’t use any library classes. It says no such files or directory if I include Standard Qt Classes libraries. What is happening?
To be frank I have no idea. Never run into the problem myself. Is it during compile you get the ‘no such file or directory’-warning? Have you made certain all include-paths are OK in the project-settings?
I got the qsqlmysqld4.dll and qsqlmysql4.dll,but when i run my application ,it always say:QMYSQL driver not loaded. What can i do?thank you
Hi,
That sounds like a search-path issue. You need to make sure that Qt’s plugin-system can find the dlls. You can do this easily by placing them in a folder called ’sqldrivers’ in the folder where the executable resides. The other way of doing it is putting the dll’s in one of the other places Qt searches for plugins. The manual says something about this.
Also, on some occations you need to clear the plugin cache. The manual has something clever to say about this too.
Good luck!
Hi,
Thank you.I’m sure that i have placed them in the folder ‘C:\Qt\2009.03\qt\plugins\sqldrivers’.I forgot to say, i got the dll by directly useing the mingw32-make.Is it the reason that qt can not read it?and another problem is that i have build the qt for three days,but when i call the mingw-32,it always show me some error.I build the qt by this step,
first,C:\qt\2009.03\qt>configure -debug-and-release -no-webkit -no-qt3support -plugin-sql-mysql
then,C:\qt\2009.03\qt>mingw32-make
is it ok?
Wish all the best withes for you!Thank you.
Thanks for your help. I got it!And i find in the qt4.5.2, there is no need for reimp to convert the dll.Just do it like this:
qmake “INCLUDEPATH+=C:\MySQL\include” “LIBS+=C:\MYSQL\MySQL Server\lib\opt\libmysql.lib” mysql.pro
mingw32-make
and then,i got the driver!
Thanks Joy and Christopher
I’ve just run the qmake with includepath and boom, there it’s.
All, just look for the %QTDIR%\src\plugins\sqldrivers\mysql and compile it with mingw and those includepaths like Joy said.
Anyway, is there any option to compile it into release dll? because it compiles debug dll. thanks a lot.
To make a release dll instead of debug, type:
mingw32-make release
I have reached till here “”"Fixing (?) QMake”"” SECTION
and got this message(see below). why so, help.
C:\Qt\2009.03\qt>cd qmake
C:\Qt\2009.03\qt\qmake>mingw32-make clean
mingw32-make: *** No rule to make target `clean’. Stop.
Have you made sure that there is a Makefile in that directory?
no there is no makefile in that directory. Is makefile an application or a g++ file.
————-
Just to infom chris, that i am working on this since a month and no hope found. I hope you are there till the conversation. cause i m not a proper programmer and i might ask you many questions. I hope I might finally get the mysql compile successfully. please help.
————-
I have :
-qt 2009.03
-mingw bin dlls(binutils-2.18.50-20080109-2.tar.gz)
-also have mingw 5.1.4 installed.
I don’t have visual basic c++(i’ve read in some sites that some make commands doesn’t work if visual basic is not installed.)
I down loaded and instatalled the QT SDK into the default location C:\QT
MySql was down loaded and installed into C:\MySQL\MySQLServer5.1\
A compromise between the recommended location of C:\MYSQL and the default
I then went through the following incantations:
C:\Qt\2009.03\qt> configure.exe -debug-and-release -plugin-sql-mysql
C:\Qt\2009.03\qt> cd src\plugins\sqldrivers\mysql
C:\Qt\2009.03\qt\src\plugins\sqldrivers\mysql> set MYSQL_PATH=C:\MySQL\MySQLServer5.1
C:\Qt\2009.03\qt\src\plugins\sqldrivers\mysql> qmake
“INCLUDEPATH+=C:\MySQL\MySQLServer5.1\include” “LIBS+=C:\MySQL\MySQLServer5.1\lib\opt\libmysql.lib” mysql.pro
————–
Originally I tried the
qmake “INCLUDEPATH+=%MYSQL_PATH%\include” “LIBS+=-L. -lmysql” mysql.pro
but this did not work
————–
C:\qt\2009.03\qt>configure -debug-and-release -no-webkit -no-qt3support -plugin-sql-mysql
C:\qt\2009.03\qt>mingw32-make
-only to end up a mysql.h error
Inspecting the compiler output immediately before the error showed that C:\MySQL\MySQLServer5.1\include was not being searched.
I am new to QT and qmake so I do not know why.
I got around this problem by copying
mysql.h
mysql_com.h
mysql_time.h
mysql_version.h
my_list.h
typelib.h
from C:\MySQL\MySQLServer5.1\include to C:\Qt\2009.03\qt\include\QtSql
and
C:\MySQL\MySQLServer5.1\lib\opt\libmysql.lib to C:\Qt\2009.03\qt\include\QtSql\
Where the compiler could find them.
A quick and dirty fix I know – but I can now link to my database!
Thanks for the help this is thh only site I’ve found that gives instructions for mere mortals.
Great tutorial, i would like to adopt your tutorial into Bahasa Indonesia in my blog, there are many QT Designer Entushiast like me that didnt have any clue about Lingking MySQL and QT Designer on Windows, thanks
If you want to trranslate it then feel free to do so. Just remember to link back here so that the people who have english as their native / second language can get to it if they find your blog first.
Also, it is Qt Creator which is bundled in the Qt SDK that I’ve talked about here, not Qt Designer. It is a little important to differentiate between those two, as they are two completely different things.
Thanks for your tutorial.really really thanks but still it shows drivers not loaded why so.i have qmysql4 and qmysqld4.dll both files in qt\plugins\sqldrivers
and mysql server installed in c:\mysql directory
plz tell all important settings, steps and a sample code for just connecting mysql server with qt program. i have a project to be submitted before 25 oct plz help me bro.i did not find reimp.and only once configured mingw32-make compiles only once correctly.i hve to re configure it all time it takes a long time.plz help me plz……
After a successful compile of Qt with the mysql-plugin you need to have both the qt-library files available in PATH, as well as the libmysql.dll (comes with MySQL). It is hard to infer from your post exactly what has gone wrong. You say you didn’t find reimp, so I’m guessing you were not able to compile it at all. You should read through the tutorial once more. I have provided links to all the tools you need, and provided a step by step guide to how you get this up and running. I followed it myself last weekend and it worked just as it should, so you’ve probably just missed a step or something.
the procedure you told i executed and it completed successfully now will u please help me to build a project for just connect mysql database and see wether connected or not:
which type of project should i chose “empty” “gui” or “qt consol” type application
what lines should i add in *.pro file.
and what are the essential code lines in main file to connect database “student” with user “root” password “password” and host as “localhost”. I have a code may i send it to you so that u can tell me the errors and lines which should be added.
Please bro help me i m in a big trouble and i have only hope with you……..
please help.
Hi again,
You should have a look at the Qt examples. All you need is there. It might also be a good idea to have a look at the manual from time to time. All you ask for is covered there.
hi can you tell me how to create a application with qt which can be run on other computers where qt is not installed or how to make an installer file independent of qt.
Again; have a look at the documentation: http://doc.trolltech.com/4.5/deployment-windows.html
Make sure to get version 0.3 of the mingw utilities.
The version 0.4-1 available for download does not work work and reports:
reimp: libmysql.lib: invalid or corrupt import library
Good point! Thanks for pointing that out.
THanks again Chris for this tutorial. I have done everything and my qt application can connect to MySql server successfully. I have three drivers loaded: QMYSQL3 QMYSQL and QSQLITE.But i have one problem. I am able to run all INSERT, CREATE TABLE, UPDATE … queries. But when I connect and try to run a SELECT query using QSqlQuery, i get an error which says:
QMYSQL3: Unable to fetch data
I thought Qt should be using the QMYSQL driver and not the QMYSQL3 driver. Do you know what could be causing this?
I am using the 2009.04 version of Qt with mysql 5.0.45
I have seen this myself, but can’t for the life of me remember what caused it or how I fixed it. Perhaps you could have a look at which files Qt loads for the various plugins and see if that gives you some clues? If you set environment variable QT_DEBUG_PLUGINS=1. The program should then spew out a whole lot of information when it loads the plugins.
Good luck!
Hi, is there a big difference, when trying this on windows 7?
Because I tried and well, didn’t work for me. I did everything as described, except the part where to fix qmake, because I got:
“mingw32-make: *** No rule to make target `clean’. Stop.”
So I did everything else as described and got many undefined references:
undefined reference to ‘vtable for WebCore::FormDataIODevice’
undefined reference to ‘vtable for WebCore::QNetworkReplyHandler’
undefined reference to ‘QWebPage::unsupportedContent(QNetworkReply*)’
undefined reference to ‘QWebPage::downloadRequested(QNetworkRequest &const)’
Funny thing, I got the MySQL driver, back when i had WinXP, but with another tutorial, unfortunately I can’t find it anymore.
I have no idea what to do now.
Maybe someone here could help, thx a lot.
hai Christ, i’m from Indonesia and i’ve follow your instruction in this tutorial.I got same problem with abdulrc.
When running command C:\Qt\2009.05\qt\qmake>mingw32-make clean
there is message : mingw32-make: *** No rule to make target `clean’. Stop.
In qmake directory there is Makefile.unix,Makefile.win32, Makefile.win32-g++,Makefile.win32-g++-sh
What should i do. Thank u in advance
Thanks a lot for this post. It has helped something I’ve been working on for a few days now.
Everything works splendidly until the end, when I try and rebuild qt.
Upon running mingw32-make sub-src, I get normal building messages until it comes up with over 1000 errors along the lines of:
Undefined refernce to QByteArray
I have scoured the Internet for a solution, but I can find none. It seems to be a linker error. Any ideas?
Just to infom chris, that i am working on this since a month and no hope found. I hope you are there till the conversation. cause i m not a proper programmer and i might ask you many questions. I hope I might finally get the mysql compile successfully. please help.
Thank you Thank you Thank you
It’s 4:00AM and I can now go to bed. Aside from the missing slashes, your tutorial for building the MySQL drivers worked perfectly. However, I had to find a windoze box with the MySQL server installed in order to find the libmysql.dll (the piece that I was missing on the target machine which has kept me up so late). I really appreciate you efforts!
Great job!
Unknown command “reimp”
And I thought I’d finally be able to get it working. Nice tutorial, though.
Uh. Got it working now. The MinGW-Utils link you are providing in your tutorial leads to the wrong MinGW stuff, whatever it is. This appears to be correct: http://sourceforge.net/projects/mingw/files/MinGW/Utilities/mingw-utils/mingw-utils-0.3/mingw-utils-0.3.tar.gz/download
It also is version 0.3, as you said was the most recent as of you writing this tutorial up. Now I think I fucked up my PATH variable by doing PATH+=somepathhere, which set path to “+” instead of adding the given path semicolon-separated.
When doing qmake “INCLUDEPATH+=%MYSQL_PATH%\include” “LIBS+=L. -lmysql” mysql.pro in the Qt Command Prompt now, it gives me an error message box saying “Could not find libgcc_s_dw2-1.dll”. What’s broken?
Appears I was using the ‘wrong’ qmake (C:\Qt\2010.04\qt\qmake\qmake.exe) while this was correct: C:\Qt\2010.04\qt\bin\qmake.exe.
So it started to seemingly compile fine, but after one minute it gave me an “moc.exe has a problem and has been terminated”-error-dialog where I may send or not send an error report to Microsoft. Is Qt’s meta-object-compiler broken? This is the last few output lines:
mingw32-make[2]: *** [tmp/moc/debug_shared/moc_qabstractanimation.cpp] Error -1073741819
mingw32-make[2]: Leaving directory `C:/Qt/2010.04/qt/src/corelib’
mingw32-make[1]: *** [debug-all] Error 2
mingw32-make[1]: Leaving directory `C:/Qt/2010.04/qt/src/corelib’
mingw32-make: *** [sub-corelib-sub_src_target_ordered] Error 2
-1073741819 smells like overflow. Something is wrong. :/
I was able to successfully build the qsqlmysql4.dll, but QMYSQL was still not recognized as a driver. After hours of website scouring I finally found that you can manually load plugins using the QPluginLoader.
QPluginLoader *thePlugin = new
QPluginLoader(“C:/qt/2009.05/qt/plugins/sqldrivers/qsqlmysqld4.dll”);
qDebug() <load();
qDebug() <isLoaded();
qDebug() <errorString();
This didn’t work, but it did give me any errorString property. The error I was getting was “module not found”. So I opened up qsqlmysqld4.dll with the Dependency Walker and found that it couldn’t find libmysql.dll. This is the dll that comes with the mysql connector so I already had it. The solution was just copying this file to the same folder where my executable was. After this it worked without an problems. I am convinced that many other people are having this same problem. Also make use of QPluginLoader.errorString. It makes troubleshooting so much easier.
Qt has a couple of paths it searches for plugins and whatnot to be included. When you distribute (or build / run on you dev-box) make sure that the required .dlls are found in one of the places Qt searches.
Read here for more details on Windows-deployment. A google-search for ‘QT_PLUGIN_PATH’ should also give you some helpful advice on the search-path-issues.
Hi,
I am using windows 7 professional 64bit, qt4.7, mysql 5.1.
I tried the steps but I have errors when I do last step:
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql>mingw32-make
Below is a snapshot of my error list:
mingw32-make[1]: Entering directory `C:/Qt/2010.05/qt/src/plugins/sqldrivers/mys
ql'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -mthreads -Wl -shared -Wl,--out-implib,c:\Qt\2010.05\qt\plugins\sqldrivers\li
bqsqlmysqld4.a -o ..\..\..\..\plugins\sqldrivers\qsqlmysqld4.dll tmp/obj/debug_s
hared/main.o tmp/obj/debug_shared/qsql_mysql.o tmp/obj/debug_shared/moc_qsql_mys
ql.o -L"c:\Qt\2010.05\qt\lib" -L"c:\Qt\2010.05\qt\lib" tmp\obj\debug_shared\qsq
lmysqld_resource_res.o -L. -lmysql -lQtSqld4 -lQtCored4
Creating library file: c:\Qt\2010.05\qt\plugins\sqldrivers\libqsqlmysqld4.a
tmp/obj/debug_shared/qsql_mysql.o: In function `codec':
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_my
sql.cpp:223: undefined reference to `mysql_character_set_name@4'
tmp/obj/debug_shared/qsql_mysql.o: In function `qMakeError':
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_my
sql.cpp:234: undefined reference to `mysql_error@4'
tmp/obj/debug_shared/qsql_mysql.o:C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql/
../../../sql/drivers/mysql/qsql_mysql.cpp:1507: undefined reference to `mysql_re
al_escape_string@16'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysqld4.dll] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/2010.05/qt/src/plugins/sqldrivers/mysq
l'
mingw32-make: *** [debug-all] Error 2
Can someone help me out? Thank you very much
I had issues one time because I had mixed non-64 bit and 64-bit libraries. Specificly I was using the 64-bit version of the MySQL-libs which I was not able to compile / link against the particular version of Qt I was using at the time. Perhaps that is something you can check?
yes, I am using 64 bit mysql with qt sdk which includes qt libraries v 4.7. Will it have issues?
Here are possible options I can try:
1) Install 32 bit mysql
2) Can I use ocbc plugin of qt to access mysql?
I can finally use mysql! This is an alternative solution, instead of compiling your own mysql plugin, you can use the ocbc plugin of qt. The details are here
http://www.qtcentre.org/threads/26296-I-need-MySQL-driver-for-Qt-4.6-WindowsXP%2832%29-MySQL-5.1
post 6
Hello
Like franziss I get errors when trying to complie Qt.
My setup is:
* qt-sdk-win-opensource-2010.05
* mysql-5.1.34-win32
* mingw-utils-0.3
-> on win7 32
The error presents itsself like this:
C:\Qt\2010.05\qt> mingw32-make sub-src
…
…
…
cd src\script\ && mingw32-make
mingw32-make[1]: Entering directory `C:/Qt/2010.05/qt/src/script’
mingw32-make -f Makefile.Debug all
mingw32-make[2]: Entering directory `C:/Qt/2010.05/qt/src/script’
C:\Qt\2010.05\qt\bin\moc.exe -DQT_SHARED -DQT_THREAD_SUPPORT -DUNICODE -DQT_LARGEFILE_SUPPORT -DJSC=QTJSC -Djscyyparse=qtjscyyparse -Djscyylex=qtjscyy
lex -Djscyyerror=qtjscyyerror -DWTF=QTWTF -DQT_BUILD_SCRIPT_LIB -DQT_NO_USING_NAMESPACE -DQLALR_NO_QSCRIPTGRAMMAR_DEBUG_INFO -DQT_MAKEDLL -DQT_NO_CAST
_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_FAST_CONCATENATION -D_USE_MATH_DEFINES -DBUILDIN
G_QT__=1 -DWTF_USE_ACCELERATED_COMPOSITING -DUSE_SYSTEM_MALLOC -DBUILDING_QT__ -DBUILDING_JavaScriptCore -DBUILDING_WTF -DWTF_USE_JAVASCRIPTCORE_BINDI
NGS=1 -DWTF_CHANGES=1 -DNDEBUG -DJS_NO_EXPORT -DQT_DLL -DQT_CORE_LIB @tmp/moc/debug_shared/mocinclude.tmp -D__GNUC__ -DWIN32 api\qscriptextensionplugi
n.h -o tmp\moc\debug_shared\moc_qscriptextensionplugin.cpp
api\qscriptextensionplugin.h:43: Error: Undefined interface
mingw32-make[2]: *** [tmp/moc/debug_shared/moc_qscriptextensionplugin.cpp] Error 1
mingw32-make[2]: Leaving directory `C:/Qt/2010.05/qt/src/script’
mingw32-make[1]: *** [debug-all] Error 2
mingw32-make[1]: Leaving directory `C:/Qt/2010.05/qt/src/script’
mingw32-make: *** [sub-script-sub_src_target_ordered] Error 2
The file “qscriptextensionplugin.h” exists, and on line 43 it says: Q_INTERFACES(QScriptExtensionInterface:QFactoryInterface)
I don’t know how to procede. Any help would be much appreciated. THX!
building only the MySQL-plugin however works!
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql> mingw32-make
This problem already exists since Qt4.6 according to:
http://www.qtcentre.org/threads/26245-Qt-4.6-api%5Cqscriptextensionplugin.h%2843%29-Error-Undefined-interface
The suggested solution is, to delete all files in the subfolders “*/tmp/moc/” throu cygwin by “find . -path ‘*/tmp/moc/* -type f -exec rm {} \;”
did so – recompiled (4.5 hours) and it worked!
Hi! Gr8 tutorial!
I found problem at the point when running mingw32-make:
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql>mingw32-make
mingw32-make -f Makefile.Debug all
mingw32-make[1]: Entering directory `C:/Qt/2010.05/qt/src/plugins/sqldrivers/mys
ql’
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_THREAD_SUPPORT -I”..\..\..\..\include\QtCore” -I”..\..\..\..\i
nclude\QtSql” -I”..\..\..\..\include” -I”c:\Program” -I”Files\MySQL\MySQL” -I”Se
rver” -I”5.5\include” -I”..\..\..\..\include\ActiveQt” -I”tmp\moc\debug_shared”
-I”..\..\..\..\mkspecs\win32-g++” -o tmp\obj\debug_shared\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]: *** [tmp/obj/debug_shared/main.o] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/2010.05/qt/src/plugins/sqldrivers/mysq
l’
mingw32-make: *** [debug-all] Error 2
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql>
I know this is something related to path. But can’t find solution.
I also tried like someone said earlier:
C:\Qt\2010.05\qt\src\plugins\sqldrivers\mysql>qmake “INCLUDEPATH+=C:\Program Fil
es\MySQL\MySQL Server 5.5\include” “LIBS+=C:\Program Files\MySQL\MySQL Server 5.
5\lib\libmysql.lib” -o Makefile mysql.pro
Thanx in advance.
AFAIK you need to have mysql installed in a path that does not have spaces in it. I have always installed to c:\mysql instead of eg. c:\Program Files\MySQL Server 5.x\Mysql\…
Thanx christopher.
I did as u said and it worked.
hi
i´ve succesfully compiled it (great tutorial) and now i have “qsqlmysql4.dll” and “qsqlmysqld4.dll” in the directory “qt/plugins/sqldrivers”, but QtCreator keeps sayin’:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
you said something about “clear the cache plugin” but i don’t know what it means.
could you help me?
Hi,
Sorry for the late reply.
Have a look at this url: http://doc.trolltech.com/latest/deployment-plugins.html#the-plugin-cache
Short story; you need to use regedit and nuke some keys. That’s all there is to it. Oh, and use dependency-walker to make sure that all the required files are where they are needed.
Best of luck!
Hey Christopher,
at the last step when running mingw32-make. How long should it or does it take to build the plugin .dll files?
That depends on your hardware.
One of my older machines spent a couple of hours building Qt. My newer ( and slightly over the top fancy) build-server spends a handful of minutes. But thats with raided high-end ssd’s, and a lot of stuff happening in parallell.
‘make -j’ is my friend.
Hello
Do you have any idea why I am getting those errors? Need help please.
D:\QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql>qmake "
QL5\include" "LIBS+=C:\MYSQL5\lib\libmysql.lib" mysql.pro
WARNING: (internal):1: Unescaped backslashes are deprecated.
WARNING: (internal):1: Unescaped backslashes are deprecated.
WARNING: (internal):1: Unescaped backslashes are deprecated.
Hello
Do you have any idea why I am getting those errors? Need help please.
(Sorry here the full code, ignore the previous reply)
D:\QtSDK\QtSources\4.7.3\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=C:\MyS
QL5\include" "LIBS+=C:\MYSQL5\lib\libmysql.lib" mysql.pro
WARNING: (internal):1: Unescaped backslashes are deprecated.
WARNING: (internal):1: Unescaped backslashes are deprecated.
WARNING: (internal):1: Unescaped backslashes are deprecated.
K I finally solved the issue. I found this site and followed the steps which are almost the same as here:
http://doc.trolltech.com/latest/sql-driver.html#qmysql
But since I was getting a message about doc.pri I downloaded it from this site (on the right you can see download xxxfilename as tat.gz). Download and unzip then copy the whole doc folder under QtSDK\QtSources\4.7.3:
http://qt.gitorious.org/qt-labs/simulator/trees/1bf4e3ba95ca96d311d5eb4511cd0fd9b1692ef4
I also had another problem with demos and examples because there was a warning message about not being able to find examples.pro and demos.pro. So all you have to do is to search through QtSDK folder then copy and paste them under the QtSDK\QtSources\4.7.3. Et voila!
I am sorry for not replying to your initial posts here. Glad you got it working though! The proccess for building plugins is IMHO not properly documented in the otherwise excellent Qt documentation.
Hi! im about 4 days compiling, deleting, recompiling, putting, moving, etc… and i just have the same error on QT Creator
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
“Driver not loaded Driver not loaded”
I just followed all the steps and get all the qmysql*.dll.
1st of all i’ve installed Mysql, then i created C:\Qt and then i put QT SDK 4.7.3 (c:\qt\4.7.3), then ive pasted Mingw (c:\qt\mingw) then i put mingw-utils (just bin files) into c:\qt\mingw\bin, then ive added all bin folders into PATH, do all the steps and get into C:\Qt\4.7.3\plugins\sqldrivers qsqlmysql4.dll qsqlmysqld4.dll libqsqlmysql4.a libqsqlmysqld4.a
The lat step of this tutorial tooked about 4 hours (mingw32-make step) (i have intel i3 8gigs hd raptors 11k rpm etc)
I’ve installed QT Creator without MinGw option checked (thats because i had Mingw already)
When i start QT creator all is fine, he see all the libraries, but when i try to test with an example i just get
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
“Driver not loaded Driver not loaded”
Im working on Windows 7 x64, MingW 440, Mingw Utils 0.3, Qt SDK 4.7.3 and Qt Creator 2.2.1
How can i test if the qmysql*.dll compiled in this tutorial works fine? im new in C++, but maybe you have some example to test it.
Thanks in advance and excuse my english pls
Hi there,
You probably need to clear the plugin cache. Please see this information in the Qt docs.
I hope you get it working.