我有以下源代码:
void Processmethod()
{
QDialog *ProcessMessage = new QDialog;
Ui::DialogProcessMessage *Dialog = new Ui::DialogProcessMessage();
Dialog->setupUi(ProcessMessage); //polymorphy
ProcessMessage->setModal(true);
ProcessMessage->setAttribute(Qt::WA_DeleteOnClose);
connect(Dialog->pushButtonAbort, SIGNAL(clicked()), &Prozess, SLOT(kill()));
connect(&Prozess6, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(helper()));
connect(&Prozess6, SIGNAL(error(QProcess::ProcessError)), this, SLOT(helper()));
connect(this,SIGNAL(enablePushButton(bool)),Dialog->pushButtonClose, SLOT(setEnabled(bool)));
Prozessmeldung->setModal(true);
ProcessMessage->show();
processmethodONE();
}
删除堆对象ProcessMessage(关闭时将其删除)时,如何最好地删除堆对象对话框?两个对象都必须在堆上创建。此外,类“ Ui :: DialogProcessMessage”是由ui文件直接创建的,因此每次更改ui文件时,对它的任何更改都将被删除。
最佳答案
QObject的所有实例在删除后都会发出destroyed(QObject*)
信号。将ProcessMessage
的信号连接到其他持久对象的插槽,然后从其中删除Dialog
堆对象。
参考:Qt documentation for QObject