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. Stop application from quitting when closing/destroying secondary widget

Stop application from quitting when closing/destroying secondary widget

Scheduled Pinned Locked Moved Solved General and Desktop
c++widgetclosingmain window
3 Posts 2 Posters 2.6k 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.
  • W Offline
    W Offline
    Wdowiak
    wrote on 22 Oct 2019, 22:19 last edited by
    #1

    Ok, so I have main window and settings window. The main window derives from QMainWindow whereas the settings one derives from QWidget.
    The main window contains a tray icon and can be either visible or hidden. When I close the settings window while the main window is hidden, the entire application closes. How can I stop the application from quitting when I destroy the settings widget when main window is hidden?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 22 Oct 2019, 23:26 last edited by
      #2

      By default main application event loop exits when last visible window is closed. You can disable that by setting QGuiApplication::setQuitOnLastWindowClosed to false.

      Make sure to provide some other path to exit the event loop by calling QCoreApplication::exit() e.g. via option in the tray's menu or a menu action in the main window when it is visible, or your user won't be able to exit the app.

      W 1 Reply Last reply 22 Oct 2019, 23:55
      4
      • C Chris Kawa
        22 Oct 2019, 23:26

        By default main application event loop exits when last visible window is closed. You can disable that by setting QGuiApplication::setQuitOnLastWindowClosed to false.

        Make sure to provide some other path to exit the event loop by calling QCoreApplication::exit() e.g. via option in the tray's menu or a menu action in the main window when it is visible, or your user won't be able to exit the app.

        W Offline
        W Offline
        Wdowiak
        wrote on 22 Oct 2019, 23:55 last edited by Wdowiak
        #3

        @Chris-Kawa
        Thank you, this solves the problem. As to alternative way to exit, I already have exit action on tray's menu.
        Have a nice day.

        1 Reply Last reply
        0

        3/3

        22 Oct 2019, 23:55

        • Login

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