Results 1 to 4 of 4

Thread: Thread started from main does send signal back.

  1. #1
    Join Date
    Jul 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Thread started from main does send signal back.

    Hello everybody, I need your help with Threads ...

    in the main.cpp file I start a main window, do stuff, ecc ...and a QThread to do some processing in parallel. When I exit from the menu or close the main window, in closeEvent() I send a signal to the thread to set a variable to stop the thread. The signal is received in the thread and the run() method stop working (checked). But, the signal finished() I set to be sent back to the main (once inside closeEvent()) and then check that the thread stopped, is not received. Any idea why? thx in advance,

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Thread started from main does send signal back.

    Probably after the closeEvent returns the eventLoop stop running and the exec returns.
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    edxxgardo (20th July 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Thread started from main does send signal back.

    show me your code

  5. #4
    Join Date
    Jul 2011
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Thread started from main does send signal back.

    Thx for your replay. Actually, what I did was to set a variable in the thread and in the main window. When I reach the closeEvent(), I emit a signal to sent a bool value to the thread to say "stop", and it works, I check it. But, in the same way, the thread should send back a signal (finished()) saying "I stopped" . This signal should set in the main window (via slot) another variable saying so, and it works too. But, my mistake is that I put a while(!stoppedThread); in the closeEvent() and the signal is not received. Which means that the stoppedThread variable is not set in the main window with the signal received back from the thread. What I did was to disable the while loop, put a Message Box (with an ok button) just to try and exit directly. Now the signal from the thread is received, the variable set and the thread stopped.
    Of course, there should be better ways to do it. I still have to see what to do instead of the message box before exiting. I'll have a look. If you can suggest something more efficient, it is welcome. Thx again,

Similar Threads

  1. Replies: 9
    Last Post: 10th October 2012, 22:55
  2. QThread sends signal to main thread immediatly
    By BIllNo123 in forum Newbie
    Replies: 7
    Last Post: 27th August 2010, 10:32
  3. QThread Signal Not Received By Main Thread Slot
    By EF2008 in forum Qt Programming
    Replies: 7
    Last Post: 4th June 2010, 08:06
  4. Replies: 9
    Last Post: 28th November 2009, 20:31
  5. Can you send a signal to a thread?
    By Dumbledore in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 20:31

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.