I made a custom dialog that is derived from QDialog. If i close the dialog, the destructor is not called. Here is how i open the dialog test in the class AWidget. test is a member of AWidget:
//In AWidget:
test = new myDialog();
test->show();
...
If i close this dialog, the dialog test is (of course?) is not deleted/destroyed.
I have to do it in the destructor of AWidget:
Destructor of AWdiget:
delete test;
The myDialog consumes much memory. The user behaviour is to open a myDialog, work in it, close it but to leave AWidget open.
How do i delocate the memory/ call the destructor of myDialog test when closing it?
Edit
Is there maybe a better way than:
void myDiaglog::closeEvent(QCloseEvent* event){
delete this;
}
If you want to always delete the dialog after it is closed you may use Qt::WA_DeleteOnClose:
Makes Qt delete this widget when the widget has accepted the close event (see QWidget::closeEvent()).
//In AWidget:
test = new myDialog();
test->setAttribute (Qt::WA_DeleteOnClose);
test->show();
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With