Graceful Qt application termination by unix signal

I have problems saving settings in the application. This is done in the destructors of the corresponding objects. This is a launcher, and shutdown shutdown is a standard case. The only way the application actually saves this setting is to manually close or end the session (at least on cinnamon, I think it just closes all the windows). Even sudo rebootprevents the Qt application from disconnecting from objects in the stack. Termination killall -s <signal> <app>has the same effect for SIGINT, SIGKILLand SIGTERM. How to make qt app gracefully shut down on SIGTERM? aboutToQuit is not emitted.

+2
source share
1 answer

Unfortunately, a lot of incorrect information is distributed on the Internet, which leads to undefined behavior. There is a minimal set of functions that are allowed to call the unix signal handler. They are called asynchronous signaling functions. Calling everything else, including every Qt function, results in undefined beghaviour. However, there is a way to handle unix signals in Qt. This method uses a self-propelled trick and is described in the Qt docs article “Calling Qt Functions from Unix Signal Handlers” .

, , , ::write(...) ( , ) . , QSocketNotifier. Qt, .

+2

All Articles