How to stop QFuture thread
-
@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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -
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. -
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
-
@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.