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
    Mar 2009
    Posts
    116
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

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

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

    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.

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

    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 

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

    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, 10:28
  2. How to use static mysql plugin
    By khikho in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2009, 22:44
  3. How build mysql plugin
    By MrShahi in forum Installation and Deployment
    Replies: 5
    Last Post: 8th June 2008, 01:11
  4. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 10:01
  5. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 14: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.