Results 1 to 10 of 10

Thread: Build Mysql plugin for Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    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?

  3. #3
    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"

  4. #4
    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......

  5. #5
    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.

  6. #6
    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 

  7. #7
    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
  •  
Qt is a trademark of The Qt Company.