Results 1 to 12 of 12

Thread: Querying within Threads

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Querying within Threads

    Quote Originally Posted by bera82
    qplot is an object of the ui file which is a plotting application.
    In the above code there are lineEdits for from and to dateTime which are entered by the user and accessed here.
    Then read this carefully: http://doc.trolltech.com/3.3/threads.html
    Especially the part about classes that use implicit sharing (like QString) and about classes derived from QObject.

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Re: Querying within Threads

    Hey bera82

    Remember that each connection to the DB must be uniquely named ...

    I use the following when working with dbconns inside threads:
    Qt Code:
    1. // create a unique database connection to serve this thread
    2. // two calls to rand() are a bit expensive but *effective*...
    3. // note: this is for a PostgreSQL connection ..
    4. sprintf(dbUnique, "myDB%x%x", rand(), rand() );
    5. myDB = QSqlDatabase::addDatabase ( "QPSQL", dbUnique );
    6. // set needed conn parameters here...
    7.  
    8. // whatever code...
    9. QSqlQuery query(myDB); // this is the important part: access it by its unique name.
    10.  
    11. // remember to close after you're done... (or upon the thread's destruction)
    12. myDB.close();
    To copy to clipboard, switch view to plain text mode 

    HTH,
    Pedro Doria Meunier

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01
  3. No context switch between Threads and parent ?
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 29th October 2008, 22:49
  4. Once more: Threads in Qt4
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 18:35

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.