Results 1 to 2 of 2

Thread: Problem related exiting the thread

  1. #1
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Problem related exiting the thread

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem related exiting the thread

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

    Qt Code:
    1. MyThread::setRunning(bool bRunning)
    2. {
    3. m_bRunning = bRunning;
    4. }
    5.  
    6. MyThread::run()
    7. {
    8. while (m_bRunning)
    9. {
    10. .... //work
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    When you set "m_bRunning" to false, the loop gets out, then, the "wait()" method will return.

    Qt Code:
    1. MyApp::on_StopButton_clicked()
    2. {
    3. pMyThread->setRunning(false);
    4. pMyThread->wait(); //Here the application will wait until the Thread gets out of "run()".
    5. }
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

Similar Threads

  1. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Replies: 10
    Last Post: 20th March 2007, 22:19
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. Replies: 11
    Last Post: 7th July 2006, 13:09

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.