PDA

View Full Version : can not connect to mysql using Qt help me please



abdol
14th June 2011, 00:43
Hi every one,
I am trying to build the mysql connection/drivers and connect to it using Qt (latest libraries 2.2) and mysql 5.5.13 community edition.

I have built the qt libraries and qt creator on my computer (using the method recommended in the Qt documentation, qmake, make, ...)

I also compiled mysql on my computer using mysql online documentation.

I managed to create libqsqlmysql.dylib and libqsqlmysql_debug.dylib and installed them in

/usr/local/Trolltech/Qt-4.7.3/plugins/sqldrivers

where my qt is installed. when i run the following code


#include <QtCore/QCoreApplication>
#include <QtSql>
#include <QtDebug>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase * db = new QSqlDatabase;

qDebug() << db->drivers();
qDebug() << QCoreApplication::libraryPaths();
return 1;
}


i only get
("QSQLITE", "QODBC3", "QODBC")

why mysql's driver is not loading?

I am new to Qt and my platform is mac os x 10.6.7. I appreciate your help and in need of it.

ChrisW67
14th June 2011, 03:18
Did you build the MySQL plugin against the 4.7.3 version of Qt? (I have no idea what you meant by "using Qt (latest libraries 2.2) ")
Is the MySQL library in the system library search path? If not, then the MySQL plugin will fail to load.
Is your test program built against the 4.7.3 version of Qt? Look at the library paths you printed.

abdol
14th June 2011, 06:59
Thank you Chris for the reply.
I apologize for my mistake. I missed the word QtCreator 2.2. Therefore it is the latest libraries (4.7.3) and qtcreator 2.2.
I followed the instructions given here
http://doc.qt.nokia.com/latest/sql-driver.html#qmysql

For your first question, do you mean environment paths?
2nd, yes and would you please tell me how should I look at the library paths?

These three drivers in addition to the one that I installed are all there. Here is ls result:

dhcp-85-5:sqldrivers ***$ ls
libqsqlite.dylib libqsqlmysql_debug.dylib
libqsqlite_debug.dylib libqsqlodbc.dylib
libqsqlmysql.dylib libqsqlodbc_debug.dylib

ChrisW67
14th June 2011, 07:23
I am not a Mac user, so I am not sure how OS x does its library search path.

First try:

otool -L libqsqlmysql.dylib
and see if anything is recorded as missing. This, I think, is the equivalent of "ldd" from most other UNIXes.

The search path is in a global environment variable DYLD_LIBRARY_PATH I think. Try the dyld man page.

abdol
15th June 2011, 01:11
Hi Chris,
I used otool before and this is what i got:
libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/local/Trolltech/Qt-4.7.3/lib/QtSql.framework/Versions/4/QtSql (compatibility version 4.7.0, current version 4.7.3)
/usr/local/Trolltech/Qt-4.7.3/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.7.0, current version 4.7.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
The otool (i guess) is the the same as ldd.
i also tried echo $DYLD_LIBRARY_PATH and i get empty string. Would you please tell me what value this should be set to?

abdol
15th June 2011, 16:58
Is there any one to help or give me some clues please.

wysota
15th June 2011, 20:39
From what I see otool can't find your libmysqlclient. Where is the file located? Try adding it to DYLD_LIBRARY_PATH, export the variable and try otool again.

abdol
16th June 2011, 02:14
Hi, Thank you wysota for your reply.
libmysqlclient is in /usr/local/Trolltech/Qt-4.7.3/plugins/sqldrivers
and I am did otool in this folder.

I tried to do what you said.
I don't know which file in what folder should i have to modify so that DYLD_... is changed or set permanently. when I export it, the change is temporal and when I close the terminal (exit) every thing is gone and DYLD_... is empty again.

Also I found this and I will be really thankful if you could shed some light on this:
http://stackoverflow.com/questions/3146274/is-it-ok-to-use-dyld-library-path-on-mac-os-x-and-whats-the-dynamic-library-se

wysota
16th June 2011, 10:02
libmysqlclient is in /usr/local/Trolltech/Qt-4.7.3/plugins/sqldrivers
Why did you put it there?


I don't know which file in what folder should i have to modify so that DYLD_... is changed or set permanently. when I export it, the change is temporal and when I close the terminal (exit) every thing is gone and DYLD_... is empty again.
Open the terminal, type in:
DYLD_LIBRARY_PATH=path/to/directory/containing/libmysqlclient
export DYLD_LIBRARY_PATH
otool -L path/to/the/qmysql/driver
and see what you get.

And better learn your own system if you want to be a software developer.

abdol
16th June 2011, 17:53
I followed the instructions given in online documentation.

I tried this before (as I mentioned in my previous post) but unfortunately it only changes the value for the current open terminal. I think there should be a file somewhere that holds the value for this variable that I don't know it.

I understand and appreciate your advice. Honestly, every time i post something I try to search for the answer to make sure that I am not wasting anyone's time by a question that already has been asked but for this one I had no success :(

wysota
16th June 2011, 17:58
I tried this before (as I mentioned in my previous post) but unfortunately it only changes the value for the current open terminal.
That's not the point. The point is to see if it fixes the problem. If it does, you can look for ways how to make this change permanent. If not, there is no point wasting time to follow this path.


I think there should be a file somewhere that holds the value for this variable that I don't know it.
You could add it to your ~/.bashrc, ~/.profile, /etc/profile or equivalent of Linux's /etc/ld.so.conf.

abdol
17th June 2011, 05:41
Thank you wysota,
sorry for misunderstanding, I did what you said and the result is the same as before:
libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/local/Trolltech/Qt-4.7.3/lib/QtSql.framework/Versions/4/QtSql (compatibility version 4.7.0, current version 4.7.3)
/usr/local/Trolltech/Qt-4.7.3/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.7.0, current version 4.7.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)

I therefore did some search to see if the problem is with Qt or mysql, then i figured that ( http://www.blog.bridgeutopiaweb.com/post/how-to-fix-mysql-load-issues-on-mac-os-x/ )

After linking sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib Qt now loads both of mysql drivers :p

I am now encountering another problem which the queries returned from mysql are empty.

Thank you all.

wysota
17th June 2011, 10:32
Apparently if the linking helped, then your earlier actions were simply done incorrectly as doing what we had told you to do should have made the application work.

abdol
17th June 2011, 18:19
I rebuilt the sql.pro file again and everything works perfect now. Thank you so much for your invaluable help.