14

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)
BigONotation
  • 4,406
  • 5
  • 43
  • 72

2 Answers2

21

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);
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
2

According to the Qt5 Doc

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

Charles Sun
  • 550
  • 4
  • 7