Results 1 to 14 of 14

Thread: Qt in windows and mysql !!!

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt - Windows - MySQL

    I am having trouble connecting from Qt (Windows) to my database.

    I am using MySQL and the server is running. With some GUI clients I am connecting to the database, but when I try to connect from Qt, I just cannot.

    I have included "#include <QtSql>" in my .cpp
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("localhost");
    3. db.setDatabaseName("testdata");
    4. db.setUserName("test");
    5. db.setPassword("password");
    6. bool ok = db.open();
    7. if(ok)
    8. textBrowser->append("Conection to DATABASE");
    9. else
    10. textBrowser->append("error to DATABASE");
    To copy to clipboard, switch view to plain text mode 


    I have also included "QT += sql" to my .pro

    I can compile and run the code perfectly, there is no errors in it. But, but I guess that there is no connection, because I always end up printing the "error to Database" message on the screen.


    Help please ?
    Last edited by probine; 7th December 2006 at 16:39.

  2. #2
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt in windows and mysql !!!

    I have a simple code. The idea is just to connect to the MySQL database and print a message on the screen if the connection has been successful.

    I have included in my "server.cpp" class this line:
    Qt Code:
    1. #include <QtSql>
    To copy to clipboard, switch view to plain text mode 

    The code in the same class is:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("localhost");
    3. db.setDatabaseName("test");
    4. db.setUserName("user");
    5. db.setPassword("password");
    6. bool ok = db.open();
    7. if(ok)
    8. textBrowser->append("Success");
    9. else
    10. textBrowser->append("Not database");
    To copy to clipboard, switch view to plain text mode 

    I am able to compile and also run this code. Their is no warning messages or anything like that, but it always prints "Not database" in the screen.

    What do I need to do, to have MySQL and Qt in windows running ?

  3. #3
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default MySQL plug-in for Qt ?

    I need to load the MySQL driver in Qt.

    Windows XP
    Qt 4.2.1
    MySQL 5.0

    This is the error message I get when trying to connect to the database:

    "Driver not loaded Driver not loaded"

    Please help !!!

    Where can I find or download that driver ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL plug-in for Qt ?

    Please, don't start multiple threads on the same problem. Also search the forum, because this topic was discussed several times.

    http://doc.trolltech.com/4.2/sql-dri...l-4-and-higher

  5. #5
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    I followed the instructions in how to built the plugin, but it doesn't work. I get this:

    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    mingw32-make[1]: Leaving directory `D:/qt-4.2.1/src/plugins/sqldrivers/mysql'
    mingw32-make: *** [release] Error 2

  6. #6
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    I have tried to create the dumm plug-in, but it doesn't work.

    Is it there a tutorial where someone explain in detail what to do ?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    Quote Originally Posted by probine View Post
    I followed the instructions in how to built the plugin, but it doesn't work. I get this:

    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    mingw32-make[1]: Leaving directory `D:/qt-4.2.1/src/plugins/sqldrivers/mysql'
    mingw32-make: *** [release] Error 2
    The actual error message was a bit earlier. Maybe you don't have a MySQL client library that you can link to?

  8. #8
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    What is wrong !!! What ????

    Please someone help !!!

    I have reinstalled everything, including Windows. I have nothing else in my computer than the following:

    Qt 4.2.2 and the Mingw that comes with it.
    MySQL server 5.0.27.

    I have registered the variables in the "Path", so when I type "make" or "qmake" in the console, then those commands are executed.

    Then I did this:

    cd %QTDIR%\src\plugins\sqldrivers\mysql
    qmake -o Makefile "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MySQL\lib\opt\libmysql.lib" mysql.pro
    make

    The "qmake" command is successful, but the "make" command gives me this error:

    g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt
    ime-pseudo-reloc -Wl,-s -Wl,-s -shared -Wl,--out-implib,c:\qt\plugins\sqldrivers
    \libqsqlmysql.a -o "..\..\..\..\plugins\sqldrivers\qsqlmysql.dll" tmp\obj\releas
    e_shared\main.o tmp\obj\release_shared\qsql_mysql.o tmp\obj\release_shared\moc_q
    sql_mysql.o -L"c:\qt\lib" -L"c:\qt\lib" C:\mysql\lib\opt\libmysql.lib -lQtSql4
    -lQtCore4
    Creating library file: c:\qt\plugins\sqldrivers\libqsqlmysql.a
    tmp\obj\release_shared\qsql_mysql.o(.text+0x4c):qs ql_mysql.cpp: undefined refere
    nce to `mysql_character_set_name@4'
    tmp\obj\release_shared\qsql_mysql.o(.text+0x184):q sql_mysql.cpp: undefined refer
    ence to `mysql_error@4'
    tmp\obj\release_shared\qsql_mysql.o(.text+0x19a):q sql_mysql.cpp: undefined refer
    ence to `mysql_errno@4'
    tmp\obj\release_shared\qsql_mysql.o(.text+0x6d7):q sql_mysql.cpp: undefined refer
    .
    .
    .
    continues with a long list of errors until
    .
    .
    .
    tmp\obj\release_shared\qsql_mysql.o(.text+0x72ea): qsql_mysql.cpp: undefined refe
    rence to `mysql_stmt_bind_param@8'
    collect2: ld returned 1 exit status
    make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    make[1]: Leaving directory `C:/qt/src/plugins/sqldrivers/mysql'
    make: *** [release] Error 2

    What in the world is wrong ?????

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    Quote Originally Posted by probine View Post
    "LIBS+=C:\MySQL\lib\opt\libmysql.lib"
    MinGW doesn't use .lib files. You have to create an import library from DLL.

    http://mingw.org/mingwfaq.shtml#faq-msvcdll

  10. #10
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    I just don't get it !!!

    Jacek, isn't there something simple... a command you know, so I have to avoid all that trouble ?

    I am sure there should be a simple way to do it, a linking command or something !, perhaps a .dll that I can download ?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    Quote Originally Posted by probine View Post
    a command you know, so I have to avoid all that trouble ?
    The exact commands you should run are in that FAQ entry.

    Also read this:
    http://www.qtcentre.org/forum/f-qt-p...dows-4048.html

  12. #12
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    Let me put it this way:

    How do I configure Qt to work with MySQL ?

    In Linux I could just type, I don't remember it exactly, something like:

    ./configure -static -plugin-sql-mysq -I /something/here/mysql.h -L /somathing/here/libmysqlclient

    Afte "make" and the just mentioned command, I could use Qt with Mysql.

    Now...now.... how is it done for Windows ? Should be as simple as that right ?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    Quote Originally Posted by probine View Post
    Should be as simple as that right ?
    It is, but you have to prepare libmysql.a first --- read those two links I posted earlier and you'll know how to do it.

  14. #14
    Join Date
    Mar 2006
    Posts
    58
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in windows and mysql !!!

    http://www.qtcentre.org/forum/f-inst...ighlight=mysql

    Try that thread. It was the only way I got it to work.

Similar Threads

  1. Embedded Mysql Windows Qt4.1
    By benguela in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2007, 01:13
  2. Connection to MySQL - windows
    By Peter34 in forum Qt Programming
    Replies: 18
    Last Post: 30th October 2006, 19:54
  3. Deploying with MySQL support under Windows
    By KShots in forum Installation and Deployment
    Replies: 1
    Last Post: 12th October 2006, 10:19
  4. Problems building mysql plugin for Qt 4.1.2 on windows XP
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 3
    Last Post: 17th May 2006, 16:38
  5. Qt 4.1 OS on Windows & mysql
    By neeko in forum Installation and Deployment
    Replies: 10
    Last Post: 31st January 2006, 21:22

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.