Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt applications close when selecting "shut down" in Gnome 3
QtWS25 Last Chance

Qt applications close when selecting "shut down" in Gnome 3

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 7.2k Views
  • 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.
  • J Offline
    J Offline
    Jos_k
    wrote on last edited by
    #1

    Hello,

    I know the title might sound silly, but the "shut down" button in the Gnome menu also allows to suspend the computer, in which case I'd like my application windows to stay open to be able to continue working later.

    So what happens ?
    I'm running two Qt-based applications, LyX and skype. Whenever I click on "shut down" in the Gnome menu, a dialog appears giving me the options "suspend", "hibernate", "restart", "power off" and "cancel". As a side-effect, however, the open windows of LyX and skype close as well, while those of applications like firefox, libreoffice, the terminal etc stay open.

    I'm guessing that Qt is interpreting some signal from Gnome differently (i.e. wrongly). But how to find out what is happening ?

    I'm running CentOS 7 on my machine, with GNOME version 3.8.4 ; and I've installed both qt-4.8.5-8.el7.x86_64 and qt-4.8.5-8.el7.i686 (skype needs the 32-bit version).

    Thanks,
    Jos

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Or it might also be gnome that is sending something differently. To debug this , I'd start by taking a look at the Session Management code in the xcb platform plugin

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jos_k
        wrote on last edited by
        #3

        Thank you for your reply.
        I must admit that I'm not able to grasp immediately what "taking a look at the Session Management code in the xcb platform plugin" would imply me to do ; could you be more precise ?

        To complete the information from my first post : I searched for applications that use qt, and found the same behaviour (i.e. closing as soon as the "shut down" dialog opens) with vlc. I'm surprised I couldn't find any hint on the internet, but maybe people don't suspend their computers while watching a movie ...

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          I guess people watch a movie on a computer :-)
          I can confirm that as soon as Gnome 3 shutdown dialog appears all Qt application that I tried quit immediately.
          I think both Qt5 and Qt4 are affected by this "bug".
          As SGaist suggested I added an abort() call to QXcbSessionManager::exitEventLoop and got huge backtrace from simple QMainWindow application.
          I can not tell why this happens.
          Is it incorrect signal from Gnome or incorrect signal processing in Qt code.

          [EDIT]: From an application point of view this exit looks like legitimate exit with return code 0.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            After several attempts to show close a shutdown dialog I've got an error on starting gvim.
            @
            ICE default IO error handler doing an exit(), pid = 15232, errno = 4
            @

            and from my test application
            @
            ICE default IO error handler doing an exit(), pid = 15251, errno = 2
            @

            errno = 2 (No such file or directory)
            errno = 4 (Interrupted system call)

            I guess session manager stuck in some intermediate state because Qt app exit without releasing some session manager handlers or something like this.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jos_k
              wrote on last edited by
              #6

              Thanks for confirming the behaviour !
              I got a similar error as yours while running LyX from within gdb, except that errno = 0 :

              @(gdb) run
              Starting program: /usr/bin/lyx
              [Thread debugging using libthread_db enabled]
              Using host libthread_db library "/lib64/libthread_db.so.1".
              ICE default IO error handler doing an exit(), pid = 5427, errno = 0
              [Inferior 1 (process 5427) exited with code 01]
              (gdb)@

              In this case, the GNOME's shutdown dialog didn't show up anymore.
              But I haven't been able to determine the conditions under which this happens.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You could try the technique described in the "Session Management" management chapter. Might give some hints of what is going on

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andreyc
                  wrote on last edited by
                  #8

                  Looks like if Qt application does not implement a session management then Qt will force such app to quit on any request from Session Manager.
                  To avoid it the application must implement something like this "example":http://qt-project.org/doc/qt-5/qsessionmanager.html#allowsInteraction

                  Gnome3 sends a SM "SaveYourself" request before showing a "Shutdown" or "Logout" dialog and it kills Qt apps without session management.

                  I guess neither LyX nor skype implement a session management as it is suggested in "Getting Session Management to Work with Qt":http://qt-project.org/doc/qt-5/session.html#getting-session-management-to-work-with-qt

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jos_k
                    wrote on last edited by
                    #9

                    Thanks, it looks like we're getting somewhere !

                    I found the following code in LyX's source :
                    @void GuiApplication::commitData(QSessionManager & sm)
                    {
                    /// The implementation is required to avoid an application exit
                    /// when session state save is triggered by session manager.
                    /// The default implementation sends a close event to all
                    /// visible top level widgets when session managment allows
                    /// interaction.
                    /// We are changing that to close all wiew one by one.
                    /// FIXME: verify if the default implementation is enough now.
                    #ifdef QT_NO_SESSIONMANAGER
                    #ifndef _MSC_VER
                    #warning Qt is compiled without session manager
                    #else
                    #pragma message("warning: Qt is compiled without session manager")
                    #endif
                    (void) sm;
                    #else
                    if (sm.allowsInteraction() && !closeAllViews())
                    sm.cancel();
                    #endif
                    }
                    @

                    If I get it right, this seems to be a bit too straightforward...
                    I'm not sure if I can rewrite this myself, but I can certainly try to get the attention of the LyX developers.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Sure you can, it's just a slot you need to have somewhere and make the connection, no need to subclass QApplication or QGuiApplication

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        Jos_k
                        wrote on last edited by
                        #11

                        OK, you encouraged me to take a closer look, but I don't understand the rationale.
                        I don't want direct user interaction, which is what the "QSessionManager::allowsInteraction()" seems to test for, just it to handle GNOME signals correctly.

                        Anyway, I started putting the slot in the lyx code though, but I'm not used to C++, so I'm having a hard time figuring out what variables should be declared, inherited ... in short, I don't know what part of the example code is universal and what part is application-specific. It's not just a matter of copy-and-paste ...

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andreyc
                          wrote on last edited by
                          #12

                          [quote author="Jos_k" date="1411368631"]
                          I found the following code in LyX's source :
                          @void GuiApplication::commitData(QSessionManager & sm)
                          {
                          if (sm.allowsInteraction() && !closeAllViews())
                          sm.cancel();
                          }
                          @
                          [/quote]

                          This is exactly what Qt doc recommends to do.
                          A connect from qApp should be somewhere in the code.
                          @
                          connect(qApp, SIGNAL(commitDataRequest(QSessionManager)), this, SLOT(commitData(QSessionManager)));
                          @
                          where this is a pointer to GuiApplication.

                          But it will not help to avoid closing an application on "Shutdown" or "Logout" dialog if all data is already saved.
                          Since Gnome3 sends these requests before showing a dialog Qt app with all data saved will quit without any questions.

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            Jos_k
                            wrote on last edited by
                            #13

                            I didn't find the "connect to slot" line in the code. I might try to find how to construct a pointer to a void function in c++, if I have some time left today.

                            As you seem to confirm, it's not only about allowing user interaction, but also about correctly handling GNOME's signals before interaction.
                            But if a prompt allowing me to save unsaved changes would show up when the dialog appears, this would already help a lot.

                            For the moment, I work around this problem by suspending the computer directly by pushing the power button ; the LyX window survives.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Did you also brought that to the Gnome team ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                Jos_k
                                wrote on last edited by
                                #15

                                No ; there seems to be no official forum, and I don't know if filing a bug report is appropriate as only Qt-based applications are affected.
                                But if you know a place where there's any chance to get an answer, I can surely open a topic.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  "Gnome mailing lists":https://mail.gnome.org/mailman/listinfo
                                  "IRC Channel":https://wiki.gnome.org/Community/GettingInTouch/IRC

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    Jos_k
                                    wrote on last edited by
                                    #17

                                    Yes, I found the gnome mailing lists ... but the plural is important here, as there seem to hundreds of lists, each related to a gnome application or functionality. What would be the right list ? A guess : gdm-list ?

                                    I'd like to avoid IRC.

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      I'd go for gnome-shell, AFAIK dgm is the part that handle drawing not session management

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • N Offline
                                        N Offline
                                        Neptilo
                                        wrote on last edited by
                                        #19

                                        Hi,

                                        I'm experiencing the same issues as described in this thread. Additionally, I'd like to mention that for some applications (for instance Qt Creator), it goes as far as shutting down the computer without waiting for the user to choose an option in the shutdown dialog. I posted "another thread":https://qt-project.org/forums/viewthread/53243 before finding this one.

                                        Are there any developments about this since September?

                                        1 Reply Last reply
                                        0
                                        • N Offline
                                          N Offline
                                          Neptilo
                                          wrote on last edited by
                                          #20

                                          Hi,

                                          I'm experiencing the same issues as described in this thread. Additionally, I'd like to mention that for some applications (for instance Qt Creator), it goes as far as shutting down the computer without waiting for the user to choose an option in the shutdown dialog. I posted "another thread":https://qt-project.org/forums/viewthread/53243 before finding this one.

                                          Are there any developments about this since September?

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved