OK Thanks.
I have decided that i whould like to wait until may thread has finished instead of exiting the thread when the user presses Cancel. How can i implement that?

Qt Code:
  1. //Slot connected to finished signal of the worker class
  2. void a::threadFinished() {
  3. m_finished = true;
  4. }
  5.  
  6. void a::cancelPressed() {
  7. //Here I would like to wait until the thread is finished.
  8. bool stopWaiting = false;
  9. while(!stopWaiting) {
  10. m_mutex.lock();
  11. if (m_finished)
  12. stopWaiting = true;
  13. m_mutex.unlock();
  14. //How shall I implement the delay (if stopWaiting is false) before i continue another loop in the whileloop without locking the entire program?
  15. }
  16.  
  17. //Do som stuff after the thread has finished.
  18.  
  19. }
To copy to clipboard, switch view to plain text mode