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. What's the "Qt Way" for handling cleanup of parentless windows?
Forum Updated to NodeBB v4.3 + New Features

What's the "Qt Way" for handling cleanup of parentless windows?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.9k Views 3 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.
  • P Offline
    P Offline
    pmh4514
    wrote on last edited by
    #1

    My application creates some "parentless windows" so that the user can drag them outside the bounds of the main window and can orient the windows in "Z" above or below the main window and the other parentless windows as desired.

    But when the user closes the main application window, I'd like all the parentless windows to be cleaned up as well. The only way I've been able to make that work is by keeping pointers to them and closing each on exit. It "works" but it doesn't feel like the right approach.. Is there a better way?

    mrjjM 1 Reply Last reply
    0
    • P pmh4514

      My application creates some "parentless windows" so that the user can drag them outside the bounds of the main window and can orient the windows in "Z" above or below the main window and the other parentless windows as desired.

      But when the user closes the main application window, I'd like all the parentless windows to be cleaned up as well. The only way I've been able to make that work is by keeping pointers to them and closing each on exit. It "works" but it doesn't feel like the right approach.. Is there a better way?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @pmh4514
      Hi
      Have you checked
      QApplication::topLevelWidgets()
      http://doc.qt.io/qt-5/qapplication.html

      like

      void showAllHiddenTopLevelWidgets()
      {
          foreach (QWidget *widget, QApplication::topLevelWidgets()) {
              if (widget->isHidden())
                  widget->show();
          }
      }
      
      1 Reply Last reply
      3
      • P Offline
        P Offline
        pmh4514
        wrote on last edited by
        #3

        Thanks! I knew there would be a "Qt Way"
        I also found QApplication::closeAllWindows

        mrjjM A 2 Replies Last reply
        3
        • P pmh4514

          Thanks! I knew there would be a "Qt Way"
          I also found QApplication::closeAllWindows

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @pmh4514
          Even better :)

          1 Reply Last reply
          1
          • P pmh4514

            Thanks! I knew there would be a "Qt Way"
            I also found QApplication::closeAllWindows

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @pmh4514 said in What's the "Qt Way" for handling cleanup of parentless windows?:

            Thanks! I knew there would be a "Qt Way"
            I also found QApplication::closeAllWindows

            If the windows have the attribute WA_DeleteOnClose set, this will also run their destructors. I am not sure whether this attribute is set by default.

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

              @Asperamanca, no it's not.

              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

              • Login

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