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:
{
// 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();
}
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();
}
To copy to clipboard, switch view to plain text mode
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();
}
void OgreThread::run()
{
QMetaObject::invokeMethod(m_pOgreManager, "render", Qt::QueuedConnection);
exec();
}
To copy to clipboard, switch view to plain text mode
Edit: Ok I had to define the connection as queued. Otherwise it will stuck forever inside the run function.
Bookmarks