I'm trying to implement a stack solution in my application so I can push and pop widgets into the stack. I'm using a QStackedWidget. When a widget is removed from the stack I want to make sure that it is also deallocated. In my code below will the pageWidget get deleted and deallocated when I run removeWidget()? Or will it be deleted when stackedWidget is deleted? How can I make it get deleted when it is removed from the stackedWidget?

Qt Code:
  1. QStackedWidget *stackedWidget = new QStackedWidget(this);
  2. QWidget *pageWidget = new QWidget(stackedWidget);
  3. stackedWidget->addWidget(pageWidget);
  4.  
  5. //Will this delete this pageWidget and deallocate memory?
  6. stackedWidget->removeWidget(pageWidget);
To copy to clipboard, switch view to plain text mode