PDA

View Full Version : [URGENT] How to connect MySQL with Qt 4.7.3?



codeartist
23rd May 2012, 17:02
Hello,

I was trying to connect my Qt code with MySQL Database. However, I got to know that only SQLite is supported in open source Qt and we need to get the drivers for MySQL on our own. Can anyone please tell me How to do it?

And most IMPORTANT: I have searched google and yahoo and a lot. All I got is simply some $QTDIR/src/plugins/ and ….
However, I don’t have any file or directory named /src/ in my Qt installation.
I am here by providing what I am using and will look forward to your suggestion:

1. Qt SDK 4.7.3
2. MySQL
3. Qt installation folder: /home/pkr/QtSDK
4. MySQL installation: /usr/share/mysql
5. OS: Ubuntu 12.04
6: DM: GNOME 3.0

Please help me out!!! It’s urgent :(

Cruz
23rd May 2012, 17:18
I don't know how much googeling you did but in the last minute I invested out of curiosity I found Qt database drivers (http://doc.qt.nokia.com/4.7-snapshot/sql-driver.html#qmysql) and MySQL Connector C++ (http://forge.mysql.com/wiki/Connector_C%2B%2B).

ChrisW67
24th May 2012, 06:43
Building the Database Plugins for QtSDK Users

codeartist
24th May 2012, 10:04
Thanks for the replies guys.
I really appreciate the help.
@ChrisW67: Can you please help me out in figuring out this problem. I need it urgently to submit my project in college. I am stuck at this point. It's too frustating. I have installed Qt 4.7.3 SDK in /home/pkr/QtSDK/....

Now after getting some response from different forum I have downloaded the sources file from here (4.8.2) (http://releases.qt-project.org/qt4/source/qt-everywhere-opensource-src-4.8.2.zip). Now I am not able to understand anything how to install it. Please help me out. I need the help and not able to understand anything. I will be greatful to you :(

ChrisW67
25th May 2012, 00:35
@ChrisW67: Can you please help me out in figuring out this problem. I need it urgently to submit my project in college.
Reminds me of some wise words, "Lack of planning on your part does not constitute an emergency on my part"

I'll highlight the section from the wiki page I wrote and linked to because I am tired of answering this question:


The first item most people notice is that the documentation refers to the Qt source at a folder called "%QTDIR%\src\plugins\sqldrivers\..." and that no such directory exists in your Qt SDK. The Qt SDK does not, by default, install the Qt source code, just a compiled version suitable for a particular compiler tool chain (MingW or MSVC). So, the first thing you need to do is download the Qt source code matching the binary version you have installed already. You do this using the Qt SDK Maintenance Tool.


Now, since you did not follow the instructions you are in a slightly different position. Unpack the source code you downloaded separately to anywhere you like. Let's say you end up with "C:\qt-everywhere-opensource-src-4.8.2" containing a few files and a bunch of directories. Just so there is no confusion, its content looks like this:


bin configure examples LGPL_EXCEPTION.txt LICENSE.LGPL README translations
changes-4.8.2 configure.exe imports lib mkspecs src util
config.profiles demos include LICENSE.FDL projects.pro templates
config.tests doc INSTALL LICENSE.GPL3 qmake tools

That directory is the equivalent of "%QTDIR%" in the documentation on building the database plugins and on the wiki page. Everything else is just following the instructions.

Also, the source code for Qt 4.8.2 you downloaded does not match the binary version of Qt you told us you were using, that is 4.7.3, in your first post. You might get away with it using this source, or you could obtain the correct source using the Qt SDK Maintenance Tool as directed.

codeartist
25th May 2012, 11:26
Really very much thanks! You are great!
Thanks for helping a novice like me. I will try not to commit such mistake again :(
Thanks :)

codeartist
26th May 2012, 15:36
C:\QtSDK\QtSources\473\src\plugins\sqldrivers\mysq l>mingw32-make


mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/QtSDK/QtSources/473/src/plugins/sqldrive
rs/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.3\mingw\include\QtCore"
-I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtSql" -I"c:\QtSDK\Desktop\Qt\4.7.3\m
ingw\include" -I"c:\Program" -I"Files\MySQL\MySQL" -I"Server" -I"5.5\include" -I
"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\ActiveQt" -I"debug" -I"c:\QtSDK\Desktop
\Qt\4.7.3\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/473/src/plugins/sqldriver
s/mysql'
mingw32-make: *** [debug] Error 2

This is the problem I am getting after I executed mingw32-make.
@Chris: Can you please help me in this?