Dialog does not close correctly
-
wrote on 16 Oct 2020, 08:04 last edited by
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.
-
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.
wrote on 16 Oct 2020, 08:08 last edited by JonB@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. -
wrote on 16 Oct 2020, 09:02 last edited by
@JonB said in Dialog does not close correctly:
Thanks, it works now.
I created a custom slot for the Cancel button in my CMyDialog class.
I this slot a put this->parentWidget()->close().
This solved the problem.
1/3