Results 1 to 8 of 8

Thread: how to reconnect CORRECTLY qmysql database?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    15
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Question how to reconnect CORRECTLY qmysql database?

    Hi all,

    I've installed qt-sdk-win-opensource-2009.05.exe and then wrote a simple program to test whether QMYSQL plugin was successfully built and connected. As of now there is no problem but I need mysql_ping functionality. How to try to reconnect correctly if isOpen function returns false?

    I've attached a part of code. Before executing a query, I want to test connectivity and reconnect if it's broken. In order to accomplish this, must removeDatabase be firstly called? Without definition of another a QSqlDatabase instance, can existing qtafx_db variable be usable? I'll pleasure so much if you can clarify this matter.

    Wish you all the best,

    Qt Code:
    1. int main (int argc, char** argv)
    2. {
    3. QCoreApplication qtafx_app (argc, argv);
    4. bool qStatus;
    5. {
    6. QSqlDatabase qtafx_db = QSqlDatabase::addDatabase ("QMYSQL");
    7. qtafx_db.setHostName ("");
    8. qtafx_db.setDatabaseName ("");
    9. qtafx_db.setUserName ("");
    10. qtafx_db.setPassword ("");
    11.  
    12. qStatus = qtafx_db.open();
    13.  
    14. ....
    15. // before executing a query, I want to test connectivity and reconnect if it's broken
    16. ....
    17.  
    18. qtafx_db.close ();
    19. qtafx_db.removeDatabase ();
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 5th January 2010 at 15:09. Reason: Missing [code] tags

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. how to reconnect CORRECTLY qmysql database?
    By yaseminyilmaz in forum Qt Programming
    Replies: 0
    Last Post: 31st December 2009, 12:20
  3. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 16:56
  4. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50

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.