Results 1 to 4 of 4

Thread: How to stop QThread?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to stop QThread?

    Accordind to Qt doc:

    To stop a thread:
    Execution ends when you return from run(), just as an application does when it leaves main()
    Concerning terminate():
    Warning: This function is dangerous and its use is discouraged. The thread can be terminate at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to cleanup after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary.
    So you can use a flag inside the run() function when you want to make it stop.
    You set this flag from outside the thread that is checked by the computation within the thread and stop the calculation if the flag is set.

    Qt Code:
    1. void myThread::run()
    2. {
    3. while (! isThreadstopped)
    4. {
    5. // do your threaded stuff;
    6. }
    7.  
    8. } // thread has terminated.
    To copy to clipboard, switch view to plain text mode 
    Last edited by toutarrive; 14th March 2010 at 07:07.

Similar Threads

  1. [QThread] Function calling after thread.stop()
    By Macok in forum Qt Programming
    Replies: 4
    Last Post: 7th February 2009, 13:33
  2. how to stop signals propagation further
    By babu198649 in forum Qt Programming
    Replies: 13
    Last Post: 27th November 2007, 10:25
  3. Replies: 1
    Last Post: 10th October 2007, 10:11
  4. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  5. Stop the thread
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 10:29

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.