Results 1 to 10 of 10

Thread: Build Mysql plugin for Qt

  1. #1
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Build Mysql plugin for Qt

    http://doc.trolltech.com/3.0/sql-driver.html#3-1

    From above site I read

    How to build the plugin on Windows

    You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MYSQL):

    cd %QTDIR%\plugins\src\sqldrivers\mysql
    qmake -o Makefile "INCLUDEPATH+=C:\MYSQL\INCLUDE" "LIBS+=C:\MYSQL\LIB\OPT\LIBMYSQL.LIB" mysql.pro
    nmake

    If you are not using a Microsoft compiler, replace nmake with make in the statement above.


    my question is From where I will get MySQL installation files????????

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Build Mysql plugin for Qt

    hmm... let me guess: http://www.mysql.com
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build Mysql plugin for Qt

    I configued Qt for Mysql using following instructons


    Creating the MySQL client library

    The client libraries (libmysql.dll and libmysql.lib) that are shipped with MySQL are compiled with the Microsoft compiler and cannot be linked using the MinGW compiler. Therefore, we first need to create a MinGW compatible library out of libmysql.dll.

    This can be done from the command line as follows:

    # cd c:\mysql\lib\opt
    # reimp -d libmysql.lib
    # dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a

    reimp is a tool to convert Microsoft's new-style (short) import libraries to be compatible with the Win32 ports of the GNU tools (MinGW, Cygwin). It reads the MS import library and writes all the library imports to a corresponding libmysql.def file used by dlltool to create the import library.

    dlltool takes the libmysql.def file that was created by reimp, and creates the GNU compatible library libmysql.a.

    Both these tools are found in mingw-utils.

    Building the QMYSQL plugin dll

    Build the Qt MySQL plugin based on the above MinGW compatible library using the following steps. This assumes that QT has been installed at C:\qt. Substitute the path that you have selected into the following commands. You need the MySQL C Include Files/Lib Files package for this step.

    # cd c:\qt\src\plugins\sqldrivers\mysql
    # qmake -o Makefile "INCLUDEPATH+=C:\MYSQL\INCLUDE" "LIBS+=-LC:\MYSQL\LIB\OPT -lmysql" mysql.pro
    # mingw32-make

    The files qsqlmysql.dll, qsqlmysqld.dll, libqsqlmysql.a, libqsqlmysqld.a will appear in your c:\qt\plugins\sqldrivers directory.

    Make sure that libmysql.dll is in your path. This is located in the C:\mysql\bin directory which can be placed in the path environment variable and is provided by the MySQL client libraries (it is also included in the Include Files/Lib Files package in the full version of MySQL5).

    I can see a libmysql.a and LIBMYSQL.def file created in C:\mysql\lib\opt\

    then I copied libmySQL.dll from c:\mysql\bin to D:\Qt\4.4.3\bin and also copied this dll where my executable resides.

    No when I query to fetch list of database drives I can see

    QSQLITE
    QMYSQL3
    QMYSQL
    QODBC3
    QODBC

    also I m able to connect to Mysql database on remot server


    But the problem is that I m not able to fetch any records from the DB..

    I use follwing code

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2.  
    3. db.setHostName("192.168.8.193");
    4. db.setDatabaseName("gaur01");
    5. db.setUserName("gaur");
    6. db.setPassword("gaur123");
    7. db.setPort(3306);
    8.  
    9.  
    10. if (!db.open()) {
    11. out <<"Error\n";
    12. out << db.lastError().driverText();
    13. out << "\n";
    14. out << db.lastError().databaseText();
    15. }
    16. else
    17. {
    18. out <<"DB open successfully";
    19. if(query.lastError().type() != QSqlError::NoError)
    20. {
    21.  
    22. out << "\nError Occured 1 : " << query.lastError().text();
    23. }
    24.  
    25. query.prepare("SELECT * FROM temp");
    26. query.exec();
    27.  
    28. if(query.lastError().type() != QSqlError::NoError)
    29. {
    30. out << "\nError Occured 2 : " << query.lastError().text();
    31. }
    To copy to clipboard, switch view to plain text mode 

    its output is
    Qt Code:
    1. DB open successfully
    2. Error Occured 1 : Driver not loaded Driver not loaded
    3. Error Occured 2 : Driver not loaded Driver not loaded
    To copy to clipboard, switch view to plain text mode 


    any help ????

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Build Mysql plugin for Qt

    can you check the returned value of query.exec() and try to read query results?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build Mysql plugin for Qt

    query.exec();

    is returning false

    and when I fetch last error using
    Qt Code:
    1. if(query.lastError().type() != QSqlError::NoError)
    2. {
    3. out << "\nError Occured 2 : " << query.lastError().text();
    4. }
    To copy to clipboard, switch view to plain text mode 

    the output is

    Error Occured 2 : Driver not loaded Driver not loaded



    what could be the possible error?

  6. #6
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build Mysql plugin for Qt

    again I followed following instructions

    ################################3
    How to Build the Plug-in

    1. Open a Qt Command Prompt and go to wherever you installed the MySQL server (C:\Program Files\MySQL\MySQL Server 5.0 is the default location).

    2. Goto the sub-directory lib/opt and run reimp libmysql.lib to produce the liblibmysql.a file. This is the import library to use with MinGW.

    3. Go to %QTDIR%/src/plugins/sqldrivers/mysql.

    4. Run the following command: qmake -o Makefile "INCLUDEPATH+=C:\Progra~1\MySQL\MySQLS~1.0\include " "LIBS+=C:\Progra~1\MySQL\MySQLS~1.0\lib\opt\liblib mysql.a" mysql.pro (Notice that the Program Files directory name has been replaced by progra~1. This is because QMake cannot handle spaces in the search paths. Use dir /X <dirname> to find the shorter 8.3 version of the name.)

    5. Run make - this should build the qsqlmysql.dll and libqsqlmysql.a files in the %QTDIR%/plugins/sqldrivers directory.

    #########################

    Till step 4 it runs successfully,but when I run make , after few hours of comiling it gives me error

    "C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\.. \mingw32\bin\ld.exe: cannot fin
    d -lmysql"


    last I could make it successfulyy but the files produced were "libqsqlmysql4.a" and "qsqlmysql4.dll"

    Now its showing me QMYSQL3 and QMYSQL in list of availabel drivers but as I execute or prepare for query it gives error "Driver not loaded"

  7. #7
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build Mysql plugin for Qt

    My problem is now,


    Its showing me MYSQL,MYSQL3 in the list of availabel drivers also allows to connect to database,but as I prepare any query or execute it it gives error "Driver not loaded"





    strange behaviour......

  8. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Build Mysql plugin for Qt

    can you show the whole code? because I can't find the place where you create the query object.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #9
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build Mysql plugin for Qt

    Qt Code:
    1. QSqlQuery query;
    2.  
    3. QFile file("d://DB_TRANS.txt");
    4. file.open(QIODevice::WriteOnly | QIODevice::Text);
    5. QTextStream out(&file);
    6.  
    7. QStringList list = QSqlDatabase::drivers();
    8. QStringList::Iterator it = list.begin();
    9. while( it != list.end() ) {
    10. out << (*it) << "\n";
    11. ++it;
    12. }
    13.  
    14. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    15.  
    16. db.setHostName("192.160.8.153");
    17. db.setDatabaseName("gaur01");
    18. db.setUserName("gaur");
    19. db.setPassword("gaur123");
    20. db.setPort(3306);
    21.  
    22. if (!db.open()) {
    23. out <<"Error\n";
    24. out << db.lastError().driverText();
    25. out << "\n";
    26. out << db.lastError().databaseText();
    27. }
    28. else
    29. {
    30. out <<"DB open successfully";
    31. if(query.lastError().type() != QSqlError::NoError)
    32. {
    33.  
    34. out << "\nError Occured 1 : " << query.lastError().text();
    35. }
    36.  
    37. if(query.prepare("SELECT * FROM temp"))
    38. out << "\nQuery prepared successfully : " ;
    39. else
    40. {
    41. out << "\nError in preparing query: " << query.lastQuery();
    42. out << query.lastError().text();
    43. }
    44.  
    45. if(query.exec())
    46. {
    47. out << "\nQuery executed successfully : " ;
    48. db.commit();
    49. }
    50.  
    51.  
    52. if(query.lastError().type() != QSqlError::NoError)
    53. {
    54.  
    55. out << "\nError Occured 2 : " << query.lastError().text();
    56. }
    To copy to clipboard, switch view to plain text mode 

    the output is
    Qt Code:
    1. QMYSQL3
    2. QMYSQL
    3. QSQLITE
    4. QODBC3
    5. QODBC
    6.  
    7. DB open successfully
    8.  
    9. Error Occured 1 : Driver not loaded Driver not loaded
    10.  
    11. Error in preparing query: Driver not loaded Driver not loaded
    12.  
    13. Error Occured 2 : Driver not loaded Driver not loaded
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Build Mysql plugin for Qt

    you are creating query (with a deafault database connection) before creating any databade connection. Try:
    Qt Code:
    1. QSqlQuery query(db);
    To copy to clipboard, switch view to plain text mode 
    after creating db.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Replies: 1
    Last Post: 14th July 2009, 09:28
  2. How to use static mysql plugin
    By khikho in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2009, 21:44
  3. How build mysql plugin
    By MrShahi in forum Installation and Deployment
    Replies: 5
    Last Post: 8th June 2008, 00:11
  4. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 09:01
  5. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 13:45

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.