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. determine source of app quiting

determine source of app quiting

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 313 Views 2 Watching
  • 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 Offline
    T Offline
    Tarae
    wrote on last edited by
    #1

    Hi,
    when I close my app by clicking at X button in the top right corner of the window (or pressing Alt + F4), I want to show a yes-no dialog "Do you really want to close the app?". I do that by overriding QMainWindow::closeEvent method.

    But when I try to turn off my pc (Windows 10) with my app still running, turning off is interrupted by this dialog. And I don't want to display dialog in this case.

    Is there a way, how to determine if app is closing because of direct user interaction (and display a dialog in this case) or because of the system turning off (and don't display dialog)?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by mchinand
      #2

      I haven't tried it, but the value of spontaneous() for the QEvent passed to closeEvent() will probably be true when it's initiated by the system shutting down.
      This doesn't work, see SGaist's comment below.

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

        Hi,

        You need to check the session management. You can then disable the custom close handling.

        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
        4
        • T Offline
          T Offline
          Tarae
          wrote on last edited by
          #4

          @mchinand thank you for the advice, but it doesn't work. spontaneous() is true even in events started by clicking the close button.

          @SGaist thank you, that's exactly what I need!

          1 Reply Last reply
          1

          • Login

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