QObjects are organized in object trees. When you create a QObject with another object as a parent, the object will automatically add itself to the children () parent list. The parent takes responsibility for the object; that is, it automatically removes its children in its destructor. See Trees and Property for more details.
Since you pass this pointer to the Test object in the constructor of AnotherClass, this means that you are using the test object as the parent of AnotherClass. Thus, deleting the Test object also removes its child and you do not need to explicitly delete the other.
However, in this case, explicit deletion in the destructor does not cause double deletion, since it causes deregistration from the children () parent list.
source share