Destructor of wxDialog Issue

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

Destructor of wxDialog Issue

Post by dhana » Wed Aug 12, 2015 6:06 am

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

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2293
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Destructor of wxDialog Issue

Post by evstevemd » Thu Aug 13, 2015 7:48 pm

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!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

Re: Destructor of wxDialog Issue

Post by whoops » Fri Aug 14, 2015 12:49 am

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 :-)
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2293
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Destructor of wxDialog Issue

Post by evstevemd » Sat Aug 15, 2015 5:31 pm

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!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

Re: Destructor of wxDialog Issue

Post by whoops » Sat Aug 15, 2015 11:55 pm

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).
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]

Post Reply