Reputation: 4499
I used the following command to create and show a window:
QGCSettingsWidget* settings = new QGCSettingsWidget(this);//here this means the mainwindow
settings->show();
The constructor is like:
QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) :
QDialog(parent, flags),
mainWindow((MainWindow*)parent),
ui(new Ui::QGCSettingsWidget)
{
ui->setupUi(this);
....
MAVLinkSettingsWidget* msettings = new MAVLinkSettingsWidget(mavlink, this);//set its parent to be this.
}
The deconstructor is:
QGCSettingsWidget::~QGCSettingsWidget()
{
delete ui;
}
However, I found that when I click the close button of the created window. Although the window disappear, the msettings is not destructed. How could I make it properly deleted?
Upvotes: 0
Views: 123
Reputation: 4344
When you close a window it is not destroyed but hides if you didn't set an attribute WA_DeleteOnClose
:
settings->setAttribute(Qt::WA_DeleteOnClose);
settings->show();
Upvotes: 1