BigONotation
BigONotation

Reputation: 4538

How to remove QObject from parent

How can I break parent-child ownership for a QObject? It seems that there is no longer an explicit way of doing this. Is it enough to call

QObject::setParent(NULL)

Upvotes: 14

Views: 5126

Answers (2)

Charles Sun
Charles Sun

Reputation: 680

According to the Qt5 Doc

You can also delete child objects yourself, and they will remove themselves from their parents.

Upvotes: 3

You're correct. To make a QObject an orphan, simply do

// on C++11 compiler
object->setParent(nullptr); 

// on a pre-C++11 compiler
object->setParent(0);

Upvotes: 21

Related Questions