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. QWidget findChildren shows non existing childs

QWidget findChildren shows non existing childs

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 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.
  • BuccaneerB Offline
    BuccaneerB Offline
    Buccaneer
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      BuccaneerB 1 Reply Last reply
      0
      • mrjjM mrjj

        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 ?

        BuccaneerB Offline
        BuccaneerB Offline
        Buccaneer
        wrote on last edited by
        #3

        @mrjj said:

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

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

          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.

          BuccaneerB 1 Reply Last reply
          0
          • BuccaneerB Buccaneer

            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 Offline
            A Offline
            alex_malyu
            wrote on last edited by alex_malyu
            #5

            @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
            0
            • mrjjM 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.

              BuccaneerB Offline
              BuccaneerB Offline
              Buccaneer
              wrote on last edited by
              #6

              @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
              0

              • Login

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