Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    5
    1338
    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.
    • V
      Violet Giraffe last edited by Violet Giraffe

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • V
          Violet Giraffe last edited by Violet Giraffe

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • V
              Violet Giraffe last edited by

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

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