简体   繁体   English

使用QMessageBox释放QPushButtons的内存

[英]Freeing Memory for QPushButtons with QMessageBox

I've instantiated a QMessageBox and added a couple of buttons to it like so: 我实例化了一个QMessageBox,并添加了几个按钮,如下所示:

QMessageBox message;
cancelButton = message.addButton(tr("Cancel"), QMessageBox::RejectRole);
okButton = message.addButton(tr("OK"), QMessageBox::ActionRole);

Is it necessary to call the destructors for each pushbutton before exiting, or does the QMessageBox destructor take care of everything? 是否有必要在退出之前为每个按钮调用析构函数,还是QMessageBox析构函数会处理所有事情?

No. 没有。

When parent objects are deleted they delete their children. 当父对象被删除时,它们将删除其子对象。 So the buttons will be deleted when 'message' is. 因此,当“消息”为时,按钮将被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM