Results 1 to 2 of 2

Thread: Thread does not join

  1. #1
    Join Date
    Feb 2009
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Thread does not join

    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:
    Qt Code:
    1. void UglyViewer::closeEvent(QCloseEvent* closeEvent)
    2. {
    3. // ask to save unsaved changes before closing the mainwindow
    4. if (destroyProject())
    5. {
    6. // this is my rendering thread
    7. m_pOgreThread->quit();
    8. m_pOgreThread->wait();
    9. closeEvent->accept();
    10. }
    11. else
    12. closeEvent->ignore();
    13. }
    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:
    Qt Code:
    1. void OgreThread::run()
    2. {
    3. QMetaObject::invokeMethod(m_pOgreManager, "render", Qt::QueuedConnection);
    4. exec();
    5. }
    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.
    Last edited by AlphaWolf; 22nd April 2009 at 00:22.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Thread does not join

    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.)

Similar Threads

  1. GUI and non-GUI thread problem
    By dimaz in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 22:25
  2. QT + OpenGL + Thread => aaaahhhhh !
    By anthibug in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2008, 14:36
  3. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 17:48
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  5. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.