How to gracefully close all dialogs on Application exit
How to gracefully close all dialogs on Application exit
Hi All,
I have a wxDialog instance which on click of a button, creates another instance of wxDialog, and this in turn creates another wxDialog on click of a button. It is basically a nested parent-child relationship.
Each wxDialog instance is a member variable of its parent class.
On application exit, should calling the Destroy() on the top-most parent wxDialog instance suffice? Will this take care of recursively calling Destroy() on all its child and grand-child dialogs?
Please let me know.
I have a wxDialog instance which on click of a button, creates another instance of wxDialog, and this in turn creates another wxDialog on click of a button. It is basically a nested parent-child relationship.
Each wxDialog instance is a member variable of its parent class.
On application exit, should calling the Destroy() on the top-most parent wxDialog instance suffice? Will this take care of recursively calling Destroy() on all its child and grand-child dialogs?
Please let me know.
Last edited by deepti on Mon Sep 17, 2018 5:38 am, edited 1 time in total.
Re: How to gracefully close all dialogs on Application exit
Hi,
How do you create those dialogs? Can you show some code?
Thank you.
How do you create those dialogs? Can you show some code?
Thank you.
Re: How to gracefully close all dialogs on Application exit
Hi,
Please find below the code explaining the creation of the dialogs.
So, there is a dialog "WxMainDialog" which has a hyperlink. On click of that, another dialog "WxAdvancedSettingsDialog" will be launched, as shown in the code below:
"m_asd" is member variable of class WxMainDialog.
The "WxAdvancedSettingsDialog" dialog has an "Edit Schedule" button. On click of that, there is another "WxScheduleDialog" dialog which will be launched, as seen below:
"m_scheduleDlg" is member variable of class "WxAdvancedSettingsDialog".
The problem is when the last dialog (WxScheduleDialog), or even the second one "WxAdvancedSettingsDialog" is kept open, and the application is exited, the app does not exit properly. It is still lingering as can be seen in the Task Manager.
So, I need a way to destroy all these dialogs from the "OnExit" function of the app, where the uppermost dialog "WxMainDialog" is destroyed.
In the destructor of "WxMainDialog", I am calling the Destroy() on "WxAdvancedSettingsDialog" instance.
And in the destructor of "WxAdvancedSettingsDialog", i am calling the Destroy() on "WxScheduleDialog" instance.
Would this suffice?
Please find below the code explaining the creation of the dialogs.
So, there is a dialog "WxMainDialog" which has a hyperlink. On click of that, another dialog "WxAdvancedSettingsDialog" will be launched, as shown in the code below:
"m_asd" is member variable of class WxMainDialog.
Code: Select all
void WxMainDialog::OnSelectiveLink(wxHyperlinkEvent& WXUNUSED(event))
{
m_asd = new WxAdvancedSettingsDialog(2, NULL);
m_asd->SetFocus();
m_asd->Raise();
if (m_asd->ShowModal() == wxID_OK)
{
}
m_asd->Destroy();
m_asd = 0;
}
The "WxAdvancedSettingsDialog" dialog has an "Edit Schedule" button. On click of that, there is another "WxScheduleDialog" dialog which will be launched, as seen below:
"m_scheduleDlg" is member variable of class "WxAdvancedSettingsDialog".
Code: Select all
void WxAdvancedSettingsDialog::OnEditActiveSyncSchedule(wxCommandEvent& event)
{
m_scheduleDlg = new WxScheduleDialog(TIME_ACTIVE_CONTROL);
m_scheduleDlg->SetFocus();
m_scheduleDlg->Raise();
m_scheduleDlg->Show(true);
.....
.....
if (m_scheduleDlg->ShowModal() == wxID_OK)
{
//do something
}
m_scheduleDlg->Destroy();
}
So, I need a way to destroy all these dialogs from the "OnExit" function of the app, where the uppermost dialog "WxMainDialog" is destroyed.
In the destructor of "WxMainDialog", I am calling the Destroy() on "WxAdvancedSettingsDialog" instance.
And in the destructor of "WxAdvancedSettingsDialog", i am calling the Destroy() on "WxScheduleDialog" instance.
Would this suffice?
Re: How to gracefully close all dialogs on Application exit
Hi,
Which window is set to be the parent for the wxAdvancedeSettings Dialog and wxScheduleDialog?
Do they have a NULL parent or some window in your program hierarchy?
Thank you.
Which window is set to be the parent for the wxAdvancedeSettings Dialog and wxScheduleDialog?
Do they have a NULL parent or some window in your program hierarchy?
Thank you.
Re: How to gracefully close all dialogs on Application exit
Yeah, they have NULL set as parent. Should that be changed to the dialog which is creating them?
Thank you!
Thank you!
Re: How to gracefully close all dialogs on Application exit
You could try wxTheApp->ExitMainLoop(). But i don't know if it works with open modal dialogs.
Use the source, Luke!
Re: How to gracefully close all dialogs on Application exit
Hi,
The wxTheApp->ExitMainLoop() call didn't help
Should i set the parent of the dialog to the one that created it?
With this, it seems to be solving the issue, but it looks kinda weird, because the main dialog of the app gets closed before the child dialogs. But the app is exiting. But, is this a clean approach?
Please let me know..
The wxTheApp->ExitMainLoop() call didn't help
Should i set the parent of the dialog to the one that created it?
With this, it seems to be solving the issue, but it looks kinda weird, because the main dialog of the app gets closed before the child dialogs. But the app is exiting. But, is this a clean approach?
Please let me know..
Re: How to gracefully close all dialogs on Application exit
Yes, it is a good approach.
Thank you.
Thank you.
-
- Earned some good credits
- Posts: 147
- Joined: Mon Sep 01, 2014 10:14 am
Re: How to gracefully close all dialogs on Application exit
Maybe you use sonething like this:
I wrote this out of my head. So something might be wrong, but i think the concept may work...
Best,
Frank
Code: Select all
void myDialog::OnCloseParent (wxEvent &ev) {
ev.Skip();
Close(); // maybe use Destoy() here
}
myDialog::myDialog (myDialog parent, ...) : wxDialog (...) {
parent->Connect(wxEVT_CLOSE, wxEvtHandler(myDialog::OnCloseParent ), NULL, this);
...
I wrote this out of my head. So something might be wrong, but i think the concept may work...
Best,
Frank