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 deleting itself when on QStackedWidget
Qt 6.11 is out! See what's new in the release blog

QWidget deleting itself when on QStackedWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.4k Views 1 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.
  • H Offline
    H Offline
    halfgaar
    wrote on last edited by
    #1

    I can't seem to find much about this in the docs, but when you have a QWidget on a QStackedWidget, does the stacked widget remove it when the widget deletes itself (and emits the destroyed signal)?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Shoudn't you just try it? I do believe that you are generating a memory leak issue here. Before you delete an object, you should verify that all used references are removed. But if you have read this:

      int QStackedWidget::addWidget(QWidget * widget)

      Appends the given widget to the QStackedWidget and returns the index position. Ownership of widget is passed on to the QStackedWidget.

      from the docs you will see that the QStackedWidget is the owner of the widget, so if you delete the widget, the parent of that widget will remove it from it's child list and I presume that it will also delete it from it's QStackedWidget list.

      Greetz, Jeroen

      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