Say we have a custom Widget that looks something along the lines of:

Qt Code:
  1. class Test : public QWidget
  2. {
  3. public:
  4. Test(QWidget *parent = nullptr) : QWidget(parent) , label(new QLabel(tr("Hello")))
  5. {
  6. QHBoxLayout *layout = new QHBoxLayout;
  7. layout->addWidget( label );
  8. setLayout( layout ); //add the current layout and widgets to be children to this(Test)
  9. }
  10. ~Test(void){}
  11. private:
  12. QLabel *label;
  13. };
To copy to clipboard, switch view to plain text mode 


What I am concerned about is memory leaking from label or layout when I delete a parent (Test) object. I tried something like:
Qt Code:
  1. ~Test( void ) { if( label ) std::cerr << "Label was not destroyed!" << std::endl; }
To copy to clipboard, switch view to plain text mode 
and the output was not what I was hoping for could this be due to me mistaking what they mean by being a parent/child or does it delete them in some random order?

Also when we have nested layouts and we destroy the parent layout are the children layouts automatically deleted also?

Something like:

Qt Code:
  1. QHBoxLayout *layout1 = new QHBoxLayout;
  2. QVBoxLayout *layout2 = new QVBoxLayout;
  3. layout2->addLayout(layout1);
  4.  
  5. //if layout2 is deleted is layout1 also?
To copy to clipboard, switch view to plain text mode 

I am used to having to manually delete heap stuff or the use of RAII not the object tree way. Thanks for any help I greatly appreciate it.