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?
//Slot connected to finished signal of the worker class
void a::threadFinished() {
m_finished = true;
}
void a::cancelPressed() {
//Here I would like to wait until the thread is finished.
bool stopWaiting = false;
while(!stopWaiting) {
m_mutex.lock();
if (m_finished)
stopWaiting = true;
m_mutex.unlock();
//How shall I implement the delay (if stopWaiting is false) before i continue another loop in the whileloop without locking the entire program?
}
//Do som stuff after the thread has finished.
}
//Slot connected to finished signal of the worker class
void a::threadFinished() {
m_finished = true;
}
void a::cancelPressed() {
//Here I would like to wait until the thread is finished.
bool stopWaiting = false;
while(!stopWaiting) {
m_mutex.lock();
if (m_finished)
stopWaiting = true;
m_mutex.unlock();
//How shall I implement the delay (if stopWaiting is false) before i continue another loop in the whileloop without locking the entire program?
}
//Do som stuff after the thread has finished.
}
To copy to clipboard, switch view to plain text mode
Bookmarks