Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 688
Tom Avatar asked Dec 10 '13 10:12

Tom


People also ask

How do I close dialog QT?

You can set Qt::WA_DeleteOnClose attribute on your dialog. This will ensure that the dialog gets deleted whenever it is closed. Then call close() method in the dialog when your button is clicked.

What is a QT dialog?

Qt provides a set of ready-made dialogs for file, font, color-selection and more. QColorDialog. Dialog widget for specifying colors. QFileDialog. Dialog that allow users to select files or directories.

How do I show dialog in Qt?

The most common way to display a modal dialog is to call its exec() function. When the user closes the dialog, exec() will provide a useful return value. Alternative way: You don't need a modal dialog. Let the dialog show modeless and connect its accepted() and rejected() signals to appropriate slots.


1 Answers

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);
like image 114
thuga Avatar answered Sep 30 '22 19:09

thuga