Tom
Tom

Reputation: 4087

How close and delete a modeless qt dialog

I have create a modeless qdialog inside a method of a class:

//Test.cpp

QDialogMaintenance *diag = new QDialogMaintenance(this);
diag->show();
diag->raise();
diag->activateWindow();

I can close the dialog only clicking on the "X" icon in the dialog frame. How can I delete the "diag" instance in the test.cpp?

Upvotes: 17

Views: 18411

Answers (1)

thuga
thuga

Reputation: 12901

You can use QWidget::setAttribute and set the Qt::WA_DeleteOnClose attribute.

Makes Qt delete this widget when the widget has accepted the close event (see QWidget::closeEvent()).

diag->setAttribute(Qt::WA_DeleteOnClose);

Upvotes: 38

Related Questions