Unsolved How to stop a delay started inside QtConcurrent thread ?
-
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 ?
-
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. -
@fcarney Thank you this helped me a lot!
-
@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.
-
@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. -
@jonB @Christian-Ehrlicher i will try to use signals and slots thank you