wxProgressDialog doesn't close

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
pbneves
Experienced Solver
Experienced Solver
Posts: 86
Joined: Fri Feb 15, 2019 11:37 am

wxProgressDialog doesn't close

Post by pbneves »

Hi everyone,

Is there some reason for wxProgressDialog doesn't close after it is been updates to his maximum value?
I have some strange behavior occurring sometimes (it is not a permanent issue). I do some calculations from values readed from a file in a multi thread process, and when a thread ends based on a wxThreadEvent handler it increments a variable and updates the wxProgressDialog.
In the text of the progress dialog appears the current stage of the calculation and it's maximum. As you can see in the image
progress.png
progress.png (29 KiB) Viewed 1768 times
all calculation are done and the wxProgressDialog has been updated, but it won't destroy itself and because it is modal the app doesn't exit of that state.
What can be wrong?
Thanks in advance.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxProgressDialog doesn't close

Post by ONEEYEMAN »

Hi,
Can you reproduce it in the dialogs sample?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxProgressDialog doesn't close

Post by doublemax »

And show some code. The wxProgressDialog should close when it goes out of scope anyway. Did you create it on the stack?
Use the source, Luke!
pbneves
Experienced Solver
Experienced Solver
Posts: 86
Joined: Fri Feb 15, 2019 11:37 am

Re: wxProgressDialog doesn't close

Post by pbneves »

No it is on the heap :( Could this be the problem?
My event handler that updates de progress bar:

Code: Select all

void MyFrame::IncrementaProgressBar()
{
	m_passosProgressBarFeitos++;
	m_progressCalculoAcumulados->Update(m_passosProgressBarFeitos, 
	wxT("Por favor espere enquanto . \nFaltam processar ")  + wxT(" (") + wxString::Format(wxT("%i"), (unsigned int) m_passosProgressBarFeitos) + wxT("/") + wxString::Format(wxT("%i"), (unsigned int) m_progressCalculoAcumulados->GetRange()) + wxT(")")
			);
	m_progressCalculoAcumulados->Fit();
}
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxProgressDialog doesn't close

Post by ONEEYEMAN »

Hi
Dialogs are not meant to be created on the heap. :D

Try to create it on stack...

Thank you.
pbneves
Experienced Solver
Experienced Solver
Posts: 86
Joined: Fri Feb 15, 2019 11:37 am

Re: wxProgressDialog doesn't close

Post by pbneves »

But creating the dialog on the heap can cause behaviors like this that I'm facing?
Because most of the times the progress dialog closes itself without issues.
Thanks,
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxProgressDialog doesn't close

Post by ONEEYEMAN »

Hi,
lease re-read my previous reply carefully, then change your code accordingly.
Keep in mind - this is not specific to progress dialogs. All dialogs needs to be made on stack.

Let us know if it fixes it.

Thank you.
pbneves
Experienced Solver
Experienced Solver
Posts: 86
Joined: Fri Feb 15, 2019 11:37 am

Re: wxProgressDialog doesn't close

Post by pbneves »

Hi,
lease re-read my previous reply carefully, then change your code accordingly.
Keep in mind - this is not specific to progress dialogs. All dialogs needs to be made on stack.
If this is a rule why in thread sample the progressBar is buit in the heap?

Code: Select all

 m_dlgProgress = new wxProgressDialog
                        (
                         wxT("Progress dialog"),
                         wxT("Wait until the thread terminates or press [Cancel]"),
                         100,
                         this,
                         wxPD_CAN_ABORT |
                         wxPD_APP_MODAL |
                         wxPD_ELAPSED_TIME |
                         wxPD_ESTIMATED_TIME |
                         wxPD_REMAINING_TIME
                        );
Or the problem is related to the wxPD_AUTO_HIDE style as I've read int other posts?
It only happens in Windows executables. I've never noticed this behavior in Linux.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxProgressDialog doesn't close

Post by doublemax »

Creating dialogs on the stack is not a rule, but it makes your life much easier. If the progressdialog doesn't close automatically, you can either try to hunt the reason down, or just close/destroy it yourself (which is what i would do).
Use the source, Luke!
pbneves
Experienced Solver
Experienced Solver
Posts: 86
Joined: Fri Feb 15, 2019 11:37 am

Re: wxProgressDialog doesn't close

Post by pbneves »

Thank you for your suggestion Doublemax.
I will follow it and I will quit using the wxPD_AUTO_HIDE style and I'll destroy the progressBar based on the steps done.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxProgressDialog doesn't close

Post by ONEEYEMAN »

Hi,
If you will make the dialog on the stack - you will not need to destroy it - it will be done automatically, when it goes out of scope.

Thank you.
pbneves
Experienced Solver
Experienced Solver
Posts: 86
Joined: Fri Feb 15, 2019 11:37 am

Re: wxProgressDialog doesn't close

Post by pbneves »

Thanks OneeYeman, but it is easier to do it on the heap because I have several threads doing the work and communicating via events when the work is done, and I cannot be stuck within the method who create de progress bar.
Post Reply