Results 1 to 5 of 5

Thread: Graceful termination of Qt application by unix signal

  1. #1
    Join Date
    Apr 2015
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Graceful termination of Qt application by unix signal

    I have problems saving settings in my application. This is done in the destructors of the relevant objects. It is a launcher and a termination by shutdown is a standard case. The only way the application actually saves the setting is by manual closing it or session shutdown (on cinnamon at least, I guess this just closes all windows). Even sudo reboot prevents the Qt application from unwinding the objects on the stack. Terminating by killall -s <signal> <app> has the same effect for SIGINT, SIGKILL and SIGTERM. How can I force my qt app to gracefully terminate at on SIGTERM? aboutToQuit is not emitted either.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graceful termination of Qt application by unix signal

    You probably need a signal handler that quits your application on SIGTERM.
    See "man signal"

    Cheers,
    _

  3. #3
    Join Date
    Apr 2015
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Graceful termination of Qt application by unix signal

    Thank you, sir.

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graceful termination of Qt application by unix signal

    Oh, and remember that you cannot do much in a signal handler, because it can be called asynchronously, for instance in the middle of some code manipulating a crucial data structure. A popular solution called the "self-pipe trick" (cf Google) consists in having the signal handler write a byte to a pipe, and the main event loop wait for read events on the other end of the pipe. In Qt, use QSocketNotifier to monitor those read events. If you are using Linux, consider using eventfd() instead of a pipe.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graceful termination of Qt application by unix signal

    Quote Originally Posted by yeye_olive View Post
    A popular solution called the "self-pipe trick"
    In Qt it should also work to post an event to an object or using QMetaObject::invokeMethod() with Qt::QueuedConnection.

    E.g.
    Qt Code:
    1. QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 20th March 2014, 07:43
  2. Long hang on application termination
    By tuli in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2013, 14:06
  3. QT Thread termination Pls help
    By dya in forum Qt Programming
    Replies: 3
    Last Post: 18th July 2011, 07:47
  4. Unix signal causing GUI to exit
    By lni in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2009, 22:28

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.