Results 1 to 5 of 5

Thread: How to detect QSqlDatabase is still open???

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Posts
    18
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default How to detect QSqlDatabase is still open???

    Hi.

    I have wrote some the thread run loop where i every iteration select some data from my database. In every iteration fisrt i check if database is open. if it open i am quering. Code looks like this.
    Qt Code:
    1. void MyThread::run()
    2. {
    3. while (m_running)
    4. {
    5. QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME);
    6.  
    7. // In this code if /etc/init.d/network stop (network closed) db.isOpen() returns true.
    8. if (db.isOpen())
    9. {
    10. QSqlQuery query1(db);
    11. // some code
    12. }
    13.  
    14. msleep(1000);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    But, for testing i close the network, in linux using /etc/init.d/network stop. In this case db.isOpen() return true and in my query.exec() my program frozes in exec code.
    How can i detect in this case that connection is stil open or network works or databse in remote server is not stopped?

    Thanks.
    Last edited by hashimov; 25th January 2011 at 08:27.

Similar Threads

  1. Replies: 3
    Last Post: 25th August 2010, 13:39
  2. QSqlDatabase::open Segfaults
    By rich.remer in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 17:32
  3. QSqlDatabase::open() fails with QODBC
    By grzywacz in forum Qt Programming
    Replies: 4
    Last Post: 7th April 2010, 04:27
  4. Why QSqlDatabase::open() returns open?
    By gboelter in forum Newbie
    Replies: 7
    Last Post: 27th August 2009, 19:52
  5. Detect which OS?
    By December in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2007, 00:01

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.