Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QApplication handling unexpected X server shutdown?

    General and Desktop
    3
    4
    2474
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      timwoj last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • R
        rcari last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • D
          dangelog last edited by

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

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply Reply Quote 0
          • T
            timwoj last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post