PDA

View Full Version : Problem related exiting the thread



raghvendramisra
16th July 2008, 09:46
Hi everyone,

I am calling a Qthread in my application by pressing a pushbutton and i am killing the thread by pressing another button.(I have give a->terminate() & a->wait() ) in my stop button.

now i was debugging a problem so used gdb to debugg. The program worked fine but when i pressed the stop button the gdb showed : Received signal SIG32......Real Time Signal32......."

plz can ne one tell me what does this mean. Once this message comes the i have to force quit my application.

Regards
Raghvendra

^NyAw^
16th July 2008, 10:10
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
}
}


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()".
}