Qt库析构函数问题

The*_*uzz 1 c++ qt destructor

我是Qt图书馆的新手,我正在进行演示.我没有使用析构函数来遇到这个类....

这是cpp文件 http://doc.trolltech.com/4.5/demos-mainwindow-mainwindow-cpp.html

这里是.h文件 http://doc.trolltech.com/4.5/demos-mainwindow-mainwindow-h.html

构造函数使用new运算符,但类没有析构函数.我错过了什么吗?

ere*_*der 12

是的,你是.Qt提供亲子关系.删除QObject时,它会自动删除其所有子项.

在下面的行中,创建一个QTextEdit,并将此指针作为其父项.

center = new QTextEdit(this); 
Run Code Online (Sandbox Code Playgroud)

因此,当删除父(MainWindow)时,也会自动删除center.看一下QObject文档.