Results 1 to 2 of 2

Thread: qThread and Unix Signals

  1. #1
    Join Date
    Mar 2008
    Qt products
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default qThread and Unix Signals


    I am having problems catching unix signals in a multithreaded application. The signals are caught fine unless I start a thread at which point the default signal handling occurs.

    To create signal handlers I am using the following code which is located in main:
    Qt Code:
    1. signal(SIGINT, shutdown);
    To copy to clipboard, switch view to plain text mode 

    This should cause the shutdown function to run on a SIGINT, however when I start a thread the above no longer works as expected. The following code is being used to start the thread:
    Qt Code:
    1. XmlRpcServer* xmlServer = new XmlRpcServer;
    2. QThread xmlServerThread;
    3. xmlServer->moveToThread(&xmlServerThread);
    4. xmlServer->connect(&xmlServerThread,
    5. SIGNAL(started()),
    6. SLOT(startServer()));
    7. xmlServerThread.start();
    To copy to clipboard, switch view to plain text mode 

    I'd be grateful for any advice anyone can offer as this has been stumping me for a while.

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: qThread and Unix Signals

    There is a whole theory on using unix signals with threads so you should first learn all that. In short it's safest to install a handler for a signal in one thread and mask out this signal in all other threads or install the same handler in all threads. The reason is that signal handlers are associated with a thread so if the signal occurs when another thread is active they will not use those custom handlers unless the thread inherited the handler bitmap from its parent thread (which would require the signal handler to be set before the new thread was spawned and assuming the operating system copies the signal mask to the new thread when clone() or equivalent is called).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.

Similar Threads

  1. Signals not working in a QThread
    By curreli in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2010, 16:04
  2. QThread SIGNALS
    By Max123 in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 13:17
  3. Replies: 7
    Last Post: 29th May 2009, 08:58
  4. QThread and signals
    By bunjee in forum Qt Programming
    Replies: 8
    Last Post: 28th March 2008, 02:44
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18

Tags for this Thread


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.