PDA

View Full Version : building mysql plugin



JeanC
7th March 2011, 10:13
Hello,

I'm trying to build the mysql plugin according to http://doc.qt.nokia.com/4.7/sql-driver.html#qmysql (thanks to schnitzel). I have used QT in the past and am slowly learning to be up and running again.

I get

jean@server:~/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql$ make
g++ -c -pipe -O2 -fvisibility=hidden -fvisibility-inlines-hidden -D_REENTRANT -Wall -W -fPIC -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtSql -I/usr/include/qt4 -I/usr/local/include -I. -o main.o main.cpp
main.cpp:42:30: error: qsqldriverplugin.h: No such file or directory
main.cpp:43:25: error: qstringlist.h: No such file or directory
In file included from main.cpp:44:

Some path issue?

Thanks.

qlands
7th March 2011, 10:29
Hi,

If you built QT from sources and the configuration located mysql then the plugin should be already built. Most of the linux distributions shipping QT have the plugin.

You are building /qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql with a version of QT in -I/usr/lib/qt4.

Please check if you don't have /usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so

Also your versions of QT in qtsdk-2010.05 and /usr/lib/qt4/ may differ.

Carlos.

JeanC
7th March 2011, 12:35
Thanks,
I downloaded the latest QT from the nokia site. The version in the ubuntu repositories is older and has problems showing help.
I do have /usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so.
When I run the demo program though (~/qtsdk-2010.05/qt/demos/sqlbrowser) I only can choose the SQLITE driver.

qlands
7th March 2011, 13:27
Is the version in qtsdk-2010.05 newer than the one in /usr/lib/qt4?

If you run qmake from the command line in ~/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql qmake will use the QT version on /usr/lib/qt4 (QTDIR)

Try by removing the Makefile and opening the .pro file in QTCreator that comes with the qtsdk-2010.05. If you build it in QT creator, it might use the qtsdk libraries and not /usr/lib/qt4

Try to also include the mysql required paths and libraries in the .pro file.

For example, it built in my distro by adding this to the .pro file:

INCLUDEPATH = /usr/local/mysql/include

Carlos.

unit
7th March 2011, 14:09
Check your mysql.pro file. And try to set QT enviroment before run qmake

JeanC
7th March 2011, 16:19
Is the version in qtsdk-2010.05 newer than the one in /usr/lib/qt4?

Don't know, how can I check that?



Try by removing the Makefile and opening the .pro file in QTCreator that comes with the qtsdk-2010.05. If you build it in QT creator, it might use the qtsdk libraries and not /usr/lib/qt4


I renamed the makefile and loaded mysql.pro into creator. I get 'no such file' on mysql.h in qsql_mysql.h:



Try to also include the mysql required paths and libraries in the .pro file.

I tried adding some paths to the pro file and run qmake again, no luck.

I found out, the docs tell you to 'qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro' but /usr/local/include is empty on my ubuntu box. And /usr/local/lib contains only a python file.
So maybe all I need to figure out is a better qmake line?

@unit, echo $QTDIR produces an ampty line, strange because I ran the installer from the nokia site.

Can anyone direct me to documentation what these environment variables should be?
Help appreciated.

qlands
7th March 2011, 17:56
Don't know, how can I check that?

If you run qmake --version you will see the version of QT. This will be your qmake in path, if you downloaded the SDK there is also a qmake in qtsdk-2010.05/qt/bin.

You can check the diferences.


I get 'no such file' on mysql.h in qsql_mysql.h

This is progress. I got the same. Add to the pro file:

INCLUDEPATH = /path/to/mysql/include (You need to have the mysql development libraries if you have ubuntu)

Then remove the Makefile. Run Qmake again and see if you have more errors.


I found out, the docs tell you to 'qmake ....

Yes because they amuse that you have set the QT enviroment before run qmake. But you have in fact two QTs. The one that ubuntu distribute and the sdk.

Carlos.

JeanC
8th March 2011, 09:43
qmake --version tells me it's using qt 4.6.2 in /usr/lib.
That's the version I got from the ubuntu repositories, but I removed that version before I downloaded the latest from nokia.com.
I guess there are leftovers.
My creator uses qt 4.7.2.
How can I remedy this mess short of reinstalling ubuntu?

As for the compile, I'm getting a bit confused, trying to build /qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql/mysqlpro now suddenly gives me a dialog with 'could not find executable, please specify one' and 'Failed to start program. Path or permissions wrong' in the application output.
I did not change anything as far as I know.

Thanks for hanging on..

Edit: on second thought, qmake was installed seperately. I have a backup machine on which I only ever installed creator from the site. It does not even have qmake installed. *even more confused*.

qlands
8th March 2011, 10:43
Hi,


How can I remedy this mess short of reinstalling ubuntu?

For me,there are two ways for fixing this:

1. Updating your QT in /usr/lib --> This will solve the problem but it will only be viable if you are not using KDE as dekstop environment or if you are using KDE 4.6.x

If you can do it, I recommend to do the following.
1.1 Download the latest QT source
1.2 Configure QT with --prefix=/usr/local/qt472 --without-phonon
1.3 Make and make install --> This will install QT 472 in /usr/local/qt472
1.4 Go to /usr/local/lib
1.5 Do: mv qt4 qt4_old --> this will backup your old qt
1.6 Do: ln -s /usr/local/qt472 ./qt4 -->Symbolic link to the new qt
If you have /usr/include/qt4
1.7 Go to /usr/include/
1.8 Do: mv qt4 qt4_old --> this will backup your old qt header files
1.9 Do: ln -s /usr/local/qt472/include ./qt4 -->Symb link to the new qt header files
1.10 In QT Creator, go to Tools -> Options -> QT4 and check the paths.
1.11. Add/update the QT versions.

With this you will have the plugin ready...

2. Setup the environment variables before you run your application. --> If you build you application with QT creator it might use the version of the SDK, but if you try to run the application from a terminal it will use to QT in path. To change this, before you run the application, you need to set QT4DIR to the proper path in your case the SDK (~/qtsdk-2010.05/qt/ i think)



... dialog with 'could not find executable ..

Maybe because you are trying to run it and not just build in it. As it is a .so ... you cannot run it. Just try to build all. If its done... and you are using shadow build (Check the projects subscreen) you will have the so in that directory.

Now, if it builds, the question is where to copy such plugin.... Check if you don't have it in ~/qtsdk-2010.05/qt/plugins/sqldrivers/ ...If you don't... so copy it there and see if the example application now detects mysql.


on second thought....

If you only have QTCreator it will try to locate qmake. If you had ubuntu it might have been in /usr/local/qt4/bin

JeanC
8th March 2011, 14:12
Succes! I now have a QMysql driver in the Sql Browser demo app!!
pheww. :)

Steps (may help others):
- install mysql headers, on ubuntu: 'sudo aptitude install libmysqld-dev'
- locate mysql.h, on ubuntu it's in /usr/include/mysql/
- add 'INCLUDEPATH = /usr/include/mysql' to (in my case) ~/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql/mysql.pro
- build all
- copy the resulting libqsqlmysql.so to ~/qtsdk-2010.05/qt/plugins/sqldrivers/

After finding out that I installed qmake separately (and forgot about it) I don't know if it's gonna bite me to have different paths. So I don't know if it's worth the trouble building qt itself again. Path settings is something I will want to look into though.

Thanks for the great help Carlos, I owe you one. :)

On to the next hurdles. :)