Hi,
Using "terminate" is not a good solution. It will KILL the thread. What you have to use is a boolean variable that is always true and when you click the pushButton you set it to false(in the run() metod):
MyThread::setRunning(bool bRunning)
{
m_bRunning = bRunning;
}
MyThread::run()
{
while (m_bRunning)
{
.... //work
}
}
MyThread::setRunning(bool bRunning)
{
m_bRunning = bRunning;
}
MyThread::run()
{
while (m_bRunning)
{
.... //work
}
}
To copy to clipboard, switch view to plain text mode
When you set "m_bRunning" to false, the loop gets out, then, the "wait()" method will return.
MyApp::on_StopButton_clicked()
{
pMyThread->setRunning(false);
pMyThread->wait(); //Here the application will wait until the Thread gets out of "run()".
}
MyApp::on_StopButton_clicked()
{
pMyThread->setRunning(false);
pMyThread->wait(); //Here the application will wait until the Thread gets out of "run()".
}
To copy to clipboard, switch view to plain text mode
Bookmarks