Page 1 of 1

Destructor of wxDialog Issue

Posted: Wed Aug 12, 2015 6:06 am
by dhana
In wxWidgets 2.8.10,


In closeEvent Function of main application ,before closing the main application destroying the opened dialog,by calling dialog->Destroy() function.
But its not calling the destructor of wxDialog.Kindly reply

Re: Destructor of wxDialog Issue

Posted: Thu Aug 13, 2015 7:48 pm
by evstevemd
where is the code?
AFAIK, destroying main frame should destroy the children.
So if you are going to close main frame there is no need to bother!

Re: Destructor of wxDialog Issue

Posted: Fri Aug 14, 2015 12:49 am
by whoops
you'd better put your code to here,
and we can analyze what happens to you application,
here is the documentation of wxWindow::Destroy():
virtual bool wxWindow::Destroy()

Destroys the window safely.

Use this function instead of the delete operator, since different window classes can be destroyed differently. Frames and dialogs are not destroyed immediately when this function is called – they are added to a list of windows to be deleted on idle time, when all the window's events have been processed. This prevents problems with events being sent to non-existent windows.

Returns
true if the window has either been successfully deleted, or it has been added to the list of windows pending real deletion.

and you may see the function bool wxWindow::Close(bool force = false), which may help you a lot :-)

Re: Destructor of wxDialog Issue

Posted: Sat Aug 15, 2015 5:31 pm
by evstevemd
whoops wrote:
and you may see the function

Code: Select all

bool wxWindow::Close(bool force = false)
, which may help you a lot :-)
In that case just hide it and it will be deleted after pending events!

Re: Destructor of wxDialog Issue

Posted: Sat Aug 15, 2015 11:55 pm
by whoops
In closeEvent Function of main application ,before closing the main application destroying the opened dialog

if the parent of the opened dialog is the main frame? that is,
wxDialog (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=wxDialogNameStr)

if parent in wxDialog is a kind of wxFrame (main frame in your application)? you should not make wxDialog's parent to NULL or (wxWindow *) 0
and you'd better show it using ShowModal() (if possible).