QApplication handling unexpected X server shutdown?



  • I have a Qt application that runs on a linux machine that displays UI windows on a Windows machine running an X server. There's a strong possibility that the users of my application will logout of Windows or kill the X server without quitting my application first.

    Is there a way to handle the unexpected shutdown of the X server, so that the application can gracefully shutdown, save stored data, etc? So far I've tried tying QApplication's aboutToQuit signal to a slot in my app, plus catching all exceptions in main. Neither worked as I expected.



  • You should look into signal handling in your process. When the X Server process terminates all its child processes (including your application) are sent a signal (I don't know which one maybe SIGKILL or SIGTERM) that you can catch and gracefully handle if you want to, default behavior is to terminate the process.
    Note that you must not call Qt code from signal handlers (they interrupt anything running in the process). You can however post messages to QObjects (that is threadsafe!) and perform an asynchronous operation in the main thread that will eventually call QApplication::quit() and terminate the process.



  • If with "unexpected shutdown" you mean a crash of the X server there's very little you can do. If it's simply saving your data when the user logs out, then just implement session management (see QSessionManager and the related docs).



  • rcari: I registered for every possible signal there is, and none of them are caught when the server shuts down.

    peppe: I mean if the user was to say, logout of Windows that's running an X server. It's not a crash on the X server's part.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.