How to stop QFuture thread
-
wrote on 16 May 2020, 06:08 last edited by Bonnie
QFurture cannot stop untill the fuction is completely executed...
Be aware that not all running asynchronous computations can be canceled. For example, the future returned by QtConcurrent::run() cannot be canceled;
QFuture::cancel()
does not stop the thread immediately, it just cancels all the unstarted jobs. -
QFurture cannot stop untill the fuction is completely executed...
Be aware that not all running asynchronous computations can be canceled. For example, the future returned by QtConcurrent::run() cannot be canceled;
QFuture::cancel()
does not stop the thread immediately, it just cancels all the unstarted jobs.wrote on 16 May 2020, 06:18 last edited by@Bonnie
thanks for the replaybut any how i want to stop it
is it have any other way to stop any process when it is running ?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
please help me to solve the problem
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -
@Bonnie
thanks for the replaybut any how i want to stop it
is it have any other way to stop any process when it is running ?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
please help me to solve the problem
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wrote on 16 May 2020, 06:20 last edited by BonnieYou can considering doing the normal way to stop a loop in another thread: adding a member variable to control the loop.
bool b_exitloop = false;
for(int i=1 ; i <= 10 && !b_exitloop;i++) { QThread::sleep(1); ui->label->setText(QString::number(i)); }
if(this->future_1.isRunning()) { this->b_exitloop = true; this->future_1.waitForFinished(); this->b_exitloop = false; }
But this cannot stop the sleep.
Also be careful about synchronizing threads if you need to. -
You can considering doing the normal way to stop a loop in another thread: adding a member variable to control the loop.
bool b_exitloop = false;
for(int i=1 ; i <= 10 && !b_exitloop;i++) { QThread::sleep(1); ui->label->setText(QString::number(i)); }
if(this->future_1.isRunning()) { this->b_exitloop = true; this->future_1.waitForFinished(); this->b_exitloop = false; }
But this cannot stop the sleep.
Also be careful about synchronizing threads if you need to.wrote on 16 May 2020, 06:32 last edited byThanks for reply
i also try this way and i get good result
but this is not a proper and good way for any large application and sensitive application
i need a proper way to solve this problem
i am also doing research for this
-
Thanks for reply
i also try this way and i get good result
but this is not a proper and good way for any large application and sensitive application
i need a proper way to solve this problem
i am also doing research for this
wrote on 16 May 2020, 06:40 last edited by Bonnie@Ketan__Patel__0011 Well, another way is to not using loop in you function and not using
run
. Try using those map functions in QtConcurrent.
Then you can cancel it. -
@Ketan__Patel__0011 Well, another way is to not using loop in you function and not using
run
. Try using those map functions in QtConcurrent.
Then you can cancel it.wrote on 16 May 2020, 06:56 last edited by@Bonnie
thanks for replywithout looping statements is not reliable to manage lot's of process
sorry but i can't remove looping statements -
wrote on 16 May 2020, 07:15 last edited by Bonnie
Then I think QtConcurrent is not the right solution for you when you need to exit a loop.
The only way to exit a loop is still controlling by a variable. -
Then I think QtConcurrent is not the right solution for you when you need to exit a loop.
The only way to exit a loop is still controlling by a variable.wrote on 16 May 2020, 07:20 last edited byLet's suppose if i use variable for controlling then when i false the any variable or boolean flag that time
is memory still consuming or not ? -
wrote on 16 May 2020, 07:30 last edited by
What memory do you mean?
-
wrote on 16 May 2020, 07:43 last edited by Ketan__Patel__0011
if i stop the any function process using any boolean flag
that time is memory(RAM) are still consuming or not ?
and CPU are still used ?
-
wrote on 16 May 2020, 20:54 last edited by
If you exit the loop, the code in the loop will stop being executed.
I don't understand what memeory / CPU are you talking about.
11/12