문제

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)
도움이 되었습니까?

해결책

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);

다른 팁

According to the Qt5 Doc

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top