Dialog does not close correctly
Solved
General and Desktop
-
Hello,
I have a dialog box with a custom "Cancel" button. The "Cancel" button clicked event is connected to the QDialog close slot.
When I click this "Cancel" button, all the widgets of the dialog box disapeared but the dialog itself does not close. When I click the cross at the top-right corner of the dialog, everything is close correctly. I don't know what I'm doing wrong. Here is a part of my code :// Open the dialog CMyDialog *child = new CMyDialog (); child->setAttribute(Qt::WA_DeleteOnClose); m_mdiArea->addSubWindow(child); child->show(); // Dialog's Constructor CMyDialog ::CMyDialog (QWidget *parent) : QDialog(parent), ui(new Ui::CMyDialog ) { ui->setupUi(this); connect(ui->m_btCancel, SIGNAL(clicked()), this, SLOT(close())); ... }
Any help is welcome. Thanks.
-
@OlivierDz
Because you are putting this dialog/window/widget into anQMdiSubWindow
you must not close the dialog itself, you must perform such operations on the MDI window which owns/shows it, That is what the the "cross" is doing. You can access the parent MDI subwindow viachild->parentWidget()
if you need to.