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?
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.
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.
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.
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);
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