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. Does QLayoutItem delete its managed item in its destructor?
Forum Updated to NodeBB v4.3 + New Features

Does QLayoutItem delete its managed item in its destructor?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutitem
4 Posts 2 Posters 870 Views 2 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.
  • - Offline
    - Offline
    -._.-
    wrote on last edited by
    #1

    I think the title states the question clearly.
    Background:
    Qt version 5.15
    The documentation of QLayoutItem doesn't say anything, but the documentation of QLayout::takeAt has an example code fragment that suggests that the managed item will not be destroyed.
    However checking my own program the debugger stack trace seems to indicate that it will be destroyed.

    I know that the answer is in the code, but sometimes Qt code can be very hard to read, so I'm hoping that someone knows the answer.

    Pl45m4P 1 Reply Last reply
    0
    • - -._.-

      I think the title states the question clearly.
      Background:
      Qt version 5.15
      The documentation of QLayoutItem doesn't say anything, but the documentation of QLayout::takeAt has an example code fragment that suggests that the managed item will not be destroyed.
      However checking my own program the debugger stack trace seems to indicate that it will be destroyed.

      I know that the answer is in the code, but sometimes Qt code can be very hard to read, so I'm hoping that someone knows the answer.

      Pl45m4P Online
      Pl45m4P Online
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      QLayoutItem does not delete anything, same as all QLayouts.
      QLayoutItems are not even QObjects, so they cant have any QWidget child widgets, which they could delete in their d'tors.
      The parent widget, on which the layout is installed, can/will delete the child widgets.

      Tips for Using Layouts

      When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed.

      Note: Widgets in a layout are children of the widget on which the layout is installed, not of the layout itself. Widgets can only have other widgets as parent, not layouts.

      https://doc.qt.io/qt-5/layout.html#tips-for-using-layouts


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      - 1 Reply Last reply
      2
      • Pl45m4P Pl45m4

        QLayoutItem does not delete anything, same as all QLayouts.
        QLayoutItems are not even QObjects, so they cant have any QWidget child widgets, which they could delete in their d'tors.
        The parent widget, on which the layout is installed, can/will delete the child widgets.

        Tips for Using Layouts

        When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed.

        Note: Widgets in a layout are children of the widget on which the layout is installed, not of the layout itself. Widgets can only have other widgets as parent, not layouts.

        https://doc.qt.io/qt-5/layout.html#tips-for-using-layouts

        - Offline
        - Offline
        -._.-
        wrote on last edited by
        #3

        @Pl45m4 said

        QLayoutItem does not delete anything, same as all QLayouts.

        QLayoutItem is not a layout, rather, it is a layout item, so I don't understand your comment.
        On the contrary, layouts are also layout items (it is so in order to allow sublayouts).

        QLayoutItems are not even QObjects, so they cant have any QWidget child widgets, which they could delete in their d'tors.
        The parent widget, on which the layout is installed, can/will delete the child widgets.

        True, they are not QObjects, but they still have a destructor.
        And they still have a managed item (unless empty), which can be a widget, layout, or spacer, according to the documentation of QLayoutItem.

        Note: Widgets in a layout are children of the widget on which the layout is installed, not of the layout itself.

        This looks useful information.
        However, I never talked about widgets.
        In fact the layout item I was using was itself a layout, I didn't mention because I didn't think it would make any difference, now I understand I should have.
        If i understand that correctly, layouts delete their child layouts in their destructor.
        Is it done through the layout item destructor?

        Pl45m4P 1 Reply Last reply
        0
        • - -._.-

          @Pl45m4 said

          QLayoutItem does not delete anything, same as all QLayouts.

          QLayoutItem is not a layout, rather, it is a layout item, so I don't understand your comment.
          On the contrary, layouts are also layout items (it is so in order to allow sublayouts).

          QLayoutItems are not even QObjects, so they cant have any QWidget child widgets, which they could delete in their d'tors.
          The parent widget, on which the layout is installed, can/will delete the child widgets.

          True, they are not QObjects, but they still have a destructor.
          And they still have a managed item (unless empty), which can be a widget, layout, or spacer, according to the documentation of QLayoutItem.

          Note: Widgets in a layout are children of the widget on which the layout is installed, not of the layout itself.

          This looks useful information.
          However, I never talked about widgets.
          In fact the layout item I was using was itself a layout, I didn't mention because I didn't think it would make any difference, now I understand I should have.
          If i understand that correctly, layouts delete their child layouts in their destructor.
          Is it done through the layout item destructor?

          Pl45m4P Online
          Pl45m4P Online
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @_ said in Does QLayoutItem delete its managed item in its destructor?:

          @Pl45m4 said

          QLayoutItem does not delete anything, same as all QLayouts.

          QLayoutItem is not a layout, rather, it is a layout item, so I don't understand your comment.
          On the contrary, layouts are also layout items (it is so in order to allow sublayouts).

          It means what it says.

          @_ said in Does QLayoutItem delete its managed item in its destructor?:

          If i understand that correctly, layouts delete their child layouts in their destructor.
          Is it done through the layout item destructor?

          Check it yourself.

          QLayoutItem destructor does basically nothing, except destroying the QLayoutItem itself

          • https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qlayoutitem.cpp.html#_ZN11QLayoutItemD1Ev

          whereas, if you delete a QLayout, it will delete all of its child-layouts, but not their widgets

          • https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qlayout.cpp.html#_ZN7QLayoutD1Ev

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          2

          • Login

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