Qt; Removing and removing QWidget. setParent (NULL) necessary?

I read about owning Qwidgets and deleting them. for example: http://qt-project.org/doc/qt-4.8/objecttrees.html

This says: "You can also delete child objects yourself, and they will be removed from their parents."

However, many of the examples I saw set the parent to null before deleting it. eg:

if (widget != NULL)
{
    layout->removeWidget(widget); 
    widget->setParent(NULL);
    delete widget;
}

Is there a need for setParent(NULL);?

It depends on whether there is a reason why I cannot just do

delete layout->itemAt(i);

or

delete layout->takeAt(i);

In fact, is there any real difference between the last two? I assume all my objects are on the heap, of course.

+4
1

NULL . .

itemAt takeAt , itemAt , takeAt , .

takeAt , . , , for ( int i = 0; i != layout->count(); ++i ), , layout->count()...

, delete layout->itemAt(i); , .

+5

All Articles