PDA

View Full Version : Thread does not join



AlphaWolf
21st April 2009, 23:00
I have a worker thread which does all the rendering using OpenGL/DirectX (support both). It renders directly into a native widget. The loop is realized using the signal/slot mechanism by emitting a signal when rendering is done which is connected to the rendering method itself.

This works fine but when I try to shut down the thread it does not work:

void UglyViewer::closeEvent(QCloseEvent* closeEvent)
{
// ask to save unsaved changes before closing the mainwindow
if (destroyProject())
{
// this is my rendering thread
m_pOgreThread->quit();
m_pOgreThread->wait();
closeEvent->accept();
}
else
closeEvent->ignore();
}

wait() never returns. But it should work because my Thread is using the Event Loop for rendering:

void OgreThread::run()
{
QMetaObject::invokeMethod(m_pOgreManager, "render", Qt::QueuedConnection);
exec();
}

Edit: Ok I had to define the connection as queued. Otherwise it will stuck forever inside the run function.

caduel
22nd April 2009, 08:09
Have you checked that your thread is actually processing its event loop?
(In case you are running some (endlessly looping) function of your own, it might just be that your threads events are never processed.)