PDA

View Full Version : Stopping a QThread



Gurdt
23rd April 2009, 14:57
Hi, while maing a project I've encountered a situation wherein i want to calculate something (lots of calculations) until it is A: done, or B: the user presses a button.
In case B, the calculation need to start all over again with new parameters

(info: calculating the solvability of a puzzle like this: http://www.quirkle.com/puzzle/)

So everytime a user presses the button I create a new QThread that wil calculate some things, but what I want, is that when a user presses the button, all active threads stops en are deleted, so there is always only one thread busy...

Is it possible to properly disable en delete a qthread??

thans for considering.

Sheng
23rd April 2009, 16:34
Hi, while maing a project I've encountered a situation wherein i want to calculate something (lots of calculations) until it is A: done, or B: the user presses a button.
In case B, the calculation need to start all over again with new parameters

(info: calculating the solvability of a puzzle like this: http://www.quirkle.com/puzzle/)

So everytime a user presses the button I create a new QThread that wil calculate some things, but what I want, is that when a user presses the button, all active threads stops en are deleted, so there is always only one thread busy...

Is it possible to properly disable en delete a qthread??

thans for considering.

You can terminate the thread by using terminate() and join(), but better to use your own parameter to control termination of the thread; And you might not want to create and delete threads every time if they are basically same, just check the status of the thread and restart it.

Gurdt
23rd April 2009, 18:16
The problem is that with terminate and join (in qt "wait' this is) it seems that I still need to wait on the threads until they finish, but I wan't to stop the current calculations en start over with new data, in the same or in another thread, it doesn't really matter

Sheng
23rd April 2009, 21:25
The problem is that with terminate and join (in qt "wait' this is) it seems that I still need to wait on the threads until they finish, but I wan't to stop the current calculations en start over with new data, in the same or in another thread, it doesn't really matter

check isRunning() method

wysota
23rd April 2009, 22:21
Are you sure you need the other thread?

Have you tried the suggestions from the QQ article about keeping your GUI responsive?