Results 1 to 2 of 2

Thread: QThread exit()/quit() question

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QThread exit()/quit() question

    Hello all,
    gotta question:
    i've started my thread, everything's great. Now I'd like to end it. Calling exit() exits the threads event loop. I assume it does so immediately. But in order to make sure that my thread really has finished, I'll need to do something like the following:
    Qt Code:
    1. int BaseDevice::stopThread ()
    2. {
    3. quit();
    4. if(wait ( interval() ))
    5. ;//ok
    6. else{
    7. log("stopThread() timed out", _TIMEOUT_ERROR);
    8. //terminate(); //dangerous
    9. }
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Thus I have a function that will wait until run() is finished. Question: does it work that way? That is, does wait() wait for event loop to exit (in which case the above doesn't work) or does it wait for run() to exit?

    thanks
    K

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread exit()/quit() question

    That is, does wait() wait for event loop to exit (in which case the above doesn't work) or does it wait for run() to exit?
    Well in the docs it says:
    bool QThread::wait ( unsigned long time = ULONG_MAX )

    Blocks the thread until either of these conditions is met:

    * The thread associated with this QThread object has finished execution (i.e. when it returns from run()). This function will return true if the thread has finished. It also returns true if the thread has not been started yet.
    * time milliseconds has elapsed. If time is ULONG_MAX (the default), then the wait will never timeout (the thread must return from run()). This function will return false if the wait timed out.

    This provides similar functionality to the POSIX pthread_join() function.

  3. The following user says thank you to high_flyer for this useful post:

    TheKedge (28th August 2006)

Similar Threads

  1. How can I get the thread ID out of QThread
    By Artschi in forum Qt Programming
    Replies: 9
    Last Post: 8th November 2017, 03:27
  2. QThread
    By TheKedge in forum Qt Programming
    Replies: 8
    Last Post: 25th August 2006, 10:29
  3. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19
  4. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.