我们有一个班级Test和一个班级AnotherClass.两者都来自QObject.
Test.h:
class Test : public QObject
{
Q_OBJECT
public:
Test(QObject* parent);
~Test();
private:
AnotherClass* other;
};
class AnotherClass : public QObject
{
Q_OBJECT
public:
AnotherClass(QObject* parent);
~AnotherClass();
};
Run Code Online (Sandbox Code Playgroud)
TEST.CPP:
Test::Test(QObject* parent) : QObject(parent)
{
other = new AnotherClass(this);
}
Test::~Test()
{
delete other;
}
Run Code Online (Sandbox Code Playgroud)
other应该在Test-instance被销毁时自动销毁,因为Test它是父other,对吧?
other通过自己在~Test()或是否处于不确定阶段退出该计划,因为它试图删除同样的对象两次?