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.
void myThread::run()
{
while (! isThreadstopped)
{
// do your threaded stuff;
}
} // thread has terminated.
void myThread::run()
{
while (! isThreadstopped)
{
// do your threaded stuff;
}
} // thread has terminated.
To copy to clipboard, switch view to plain text mode
Bookmarks