Results 1 to 14 of 14

Thread: can not connect to mysql using Qt help me please

  1. #1
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QtSql>
    3. #include <QtDebug>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8.  
    9. qDebug() << db->drivers();
    10. qDebug() << QCoreApplication::libraryPaths();
    11. return 1;
    12. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

  3. #3
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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:
    Qt Code:
    1. otool -L libqsqlmysql.dylib
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #5
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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?

  6. #6
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: can not connect to mysql using Qt help me please

    Is there any one to help or give me some clues please.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: can not connect to mysql using Qt help me please

    Quote Originally Posted by abdol View Post
    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:
    bash Code:
    1. DYLD_LIBRARY_PATH=path/to/directory/containing/libmysqlclient
    2. export DYLD_LIBRARY_PATH
    3. otool -L path/to/the/qmysql/driver
    To copy to clipboard, switch view to plain text mode 
    and see what you get.

    And better learn your own system if you want to be a software developer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    abdol (16th June 2011)

  11. #10
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: can not connect to mysql using Qt help me please

    Quote Originally Posted by abdol View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    abdol (16th June 2011)

  14. #12
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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

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

    Thank you all.

  15. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. The following user says thank you to wysota for this useful post:

    abdol (17th June 2011)

  17. #14
    Join Date
    May 2011
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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.

Similar Threads

  1. connect mysql with odbc
    By qtcoba in forum Newbie
    Replies: 2
    Last Post: 18th April 2011, 23:12
  2. How to connect Qt with MYSQL??
    By Gokulnathvc in forum Newbie
    Replies: 10
    Last Post: 24th March 2011, 00:52
  3. qt connect with mysql in fedora
    By sachinmcajnu in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2011, 19:01
  4. Qt connect different MySQL
    By weixj2003ld in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2009, 08:35
  5. How to connect MySQL with QT
    By diego in forum Qt Programming
    Replies: 0
    Last Post: 27th May 2009, 05:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.