How to stop a delay started inside QtConcurrent thread ?
- 
wrote on 19 Apr 2019, 12:44 last edited by
Hi,
i have some code running in a thread using QtConcurrent and i also use
QThread::currentThread()->msleep(650000);in order to delay a while loop for about 10 mins.. but i want to stop this delay when the application ends. could you please provide some thoughts ?
 - 
wrote on 19 Apr 2019, 14:31 last edited by
Create a loop inside your thread:
int count = 0; while(sleeping){ QThread::currentThread()->msleep(1000); // process events like signals QCoreApplication::processEvents(); count++; if(count>=650){ sleeping = false; } }Put a slot in your thread that will set sleeping to false when you want to end early. You need to process
events in order to handle a signal. At most you will wait 1 second for this to quit. Use finer grain sleep if you desire more granularity. - 
Create a loop inside your thread:
int count = 0; while(sleeping){ QThread::currentThread()->msleep(1000); // process events like signals QCoreApplication::processEvents(); count++; if(count>=650){ sleeping = false; } }Put a slot in your thread that will set sleeping to false when you want to end early. You need to process
events in order to handle a signal. At most you will wait 1 second for this to quit. Use finer grain sleep if you desire more granularity. - 
@xenovas said in How to stop a delay started inside QtConcurrent thread ?:
in order to delay a while loop for about 10 mins
Use signals and slots instead - this is not the way to go.
 - 
Hi,
i have some code running in a thread using QtConcurrent and i also use
QThread::currentThread()->msleep(650000);in order to delay a while loop for about 10 mins.. but i want to stop this delay when the application ends. could you please provide some thoughts ?
wrote on 20 Apr 2019, 09:35 last edited by@xenovas
Suggest you heed @Christian-Ehrlicher's post. Using threads/sleep/processEvents is not a good way to go when signals/slots are on offer. - 
wrote on 20 Apr 2019, 09:54 last edited by
@jonB @Christian-Ehrlicher i will try to use signals and slots thank you
 
6/6