A quick question:

QWidget::setLayout takes ownership of the layout and QLayout::addWidget takes ownership of the passed widgets. How does it know when to delete an object and when not? Or: why does this work:

Qt Code:
  1. class test : public QWidget
  2. {
  3. public:
  4. test()
  5. {
  6. l->addWidget(&bar);
  7. setLayout(l);
  8. }
  9. };
To copy to clipboard, switch view to plain text mode 


Why doesn't a double free occur, once when the layout discards the scrollbar and once when the test dtor?