Qt Forum

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

    Call for Presentations - Qt World Summit

    QWidget findChildren shows non existing childs

    General and Desktop
    3
    6
    1425
    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.
    • Buccaneer
      Buccaneer last edited by

      Hi!
      I need to catch if child widget is open and I use findChildren from parent.
      In first loop, after child widget is initialized in 1 time - I find it with findChildren, and it's ok.
      But after closing child widget with close() - the findChildren still shows child object in generated list.
      After open child widget in 2 time findChildren shows two copies of child objects.
      How findChildren works?
      Why findChildren didn't remove a non-existing child objects?

      A 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        That sounds odd.

        You are 100% sure you clear the list between calls?

        Also, close would not normally delete childs unless you are using
        Qt::WA_DeleteOnClose.

        It sounds like you create the child objects on the fly, when you show it.
        So maybe you do create them a second time and that is why there are 2 of the same.

        If you show them many times, you get many in the list or always just 2 ?

        Buccaneer 1 Reply Last reply Reply Quote 0
        • Buccaneer
          Buccaneer @mrjj last edited by

          @mrjj said:

          You are 100% sure you clear the list between calls?
          How can I clear list generated by findChildren?

          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by mrjj

            well if you do
            QList<QWidget *> widgetslist = parentWidget.findChildren( ...)

            then no need to clear it as it is created each time. (and deleted at the end of the function)

            I asked just in case you had widgetslist as part of Parent Class.
            then doing
            widgetslist .clear();
            widgetslist = parentWidget.findChildren( ...)
            Might been a cure.

            Buccaneer 1 Reply Last reply Reply Quote 0
            • A
              alex_malyu @Buccaneer last edited by alex_malyu

              @Buccaneer said:

              But after closing child widget with close() - the findChildren still shows child object in generated list.
              After open child widget in 2 time findChildren shows two copies of child objects.
              How findChildren works?
              Why findChildren didn't remove a non-existing child objects?

              findChildren does not remove anything.
              You assumed close() does, but it does not not delete widgets, it only hides them.
              So children remain, they are just not visible.

              1 Reply Last reply Reply Quote 0
              • Buccaneer
                Buccaneer @mrjj last edited by

                @mrjj said:

                Also, close would not normally delete childs unless you are using
                Qt::WA_DeleteOnClose.

                @alex_malyu

                findChildren does not remove anything.

                Thanks to everyone. Qt::WA_DeleteOnClose - that's what I looking for.
                I was not familiar with this attribute.
                mrjj and alex_malyu you are really helped me.
                Thanks

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