can not connect to mysql using Qt help me please
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
Code:
#include <QtCore/QCoreApplication>
#include <QtSql>
#include <QtDebug>
int main(int argc, char *argv[])
{
qDebug() << db->drivers();
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.
Re: can not connect to mysql using Qt help me please
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.
Re: can not connect to mysql using Qt help me please
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
Re: can not connect to mysql using Qt help me please
I am not a Mac user, so I am not sure how OS x does its library search path.
First try:
Code:
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.
Re: can not connect to mysql using Qt help me please
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?
Re: can not connect to mysql using Qt help me please
Is there any one to help or give me some clues please.
Re: can not connect to mysql using Qt help me please
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.
Re: can not connect to mysql using Qt help me please
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/3...mic-library-se
Re: can not connect to mysql using Qt help me please
Quote:
Originally Posted by
abdol
libmysqlclient is in /usr/local/Trolltech/Qt-4.7.3/plugins/sqldrivers
Why did you put it there?
Quote:
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:
Code:
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.
Re: can not connect to mysql using Qt help me please
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 :(
Re: can not connect to mysql using Qt help me please
Quote:
Originally Posted by
abdol
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.
Quote:
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.
Re: can not connect to mysql using Qt help me please
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/...s-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.
Re: can not connect to mysql using Qt help me please
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.
Re: can not connect to mysql using Qt help me please
I rebuilt the sql.pro file again and everything works perfect now. Thank you so much for your invaluable help.