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. Showing and then closing a QDialog in an application with hidden main window results in the app exiting
QtWS25 Last Chance

Showing and then closing a QDialog in an application with hidden main window results in the app exiting

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.8k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by Violet Giraffe
    #1

    I have a tray icon-based application. Most of the time its main window is hidden, and only comes up when needed. Now, when I exec a QDialog from the tray menu, the app exits once the dialog closes, which is wrong.
    I guess I know where this issue is coming from: the application closes once the last of its windows has been closed. The catch is that the main window has never been shown in the first place yet! I don't call any of the show...() functions after creating the window. When I need the window, I show it and then hide back when I no longer need it.

    Can I circumvent the app exit issue? I really need a couple dialogs.

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

      Hi,

      You must set the quitOnLastWindowClosed property to false to avoid your application to quit.

      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
      1
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by Violet Giraffe
        #3

        Hi, thank you, that is an acceptable workaround. But I believe it's a bug in Qt. The docs say: "The application quits when the last visible primary window (i.e. window with no parent) is closed." Not only has my main window not been closed (because it's never even been shown yet), but also, the dialogs that I create and closing which causes the app to quit are NOT primary windows. They all have the main window as a parent.

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

          No it's not, take a look at the System Tray Icon example. That's exactly how it's done.

          Your dialog is the last visible primary window since it's the only window shown by your application. What's between the parenthesis in the documentation just state the usual case: you start your application by showing your main window which generally doesn't have any parent.

          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
          1
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            I see. Then it's just the case of the docs not being clear.

            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