wxWizard closing entire app on finish Topic is solved

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
Elured42
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Oct 15, 2021 2:58 am

wxWizard closing entire app on finish

Post by Elured42 »

I am using a wxWizard and when it reaches the end, on finish it closes the entire app instead of just the wxwizard and I don't know why.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: wxWizard closing entire app on finish

Post by Kvaz1r »

Show your code for reproducing the behaviour and check the wizard sample.
Also there is wxWizard tutorial
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxWizard closing entire app on finish

Post by PB »

Is the wizard the only window the app has, if so perhaps, the wxApp considers the wizard its top-level window and exits when it is closed?

Whatever it is, it should be easy to see what is going on with a debugger.
Elured42
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Oct 15, 2021 2:58 am

Re: wxWizard closing entire app on finish

Post by Elured42 »

Turns out it was not the wxWizard that was the problem. I was using a Main Menu to create a wxDialog box to determine which wizard to use. When the Dialog was done it was closing everything instead of just the Dialog frame. Using this->Close(); instead of Destroy() seems to solve the problem but then the entire app won't close when using the main menu's EXIT Button.

The Dialog, Wizard and main menu all have their own individual parent frames and should not be linked to each other by parent frames.

Dialog creation from main menu

Code: Select all

void MainFrame::OnNewChar(wxCommandEvent&event)
{
    wxFrame *CharCreatorSelection =new wxFrame(NULL,-1,"",wxPoint(0,0),g_mainmenusize,wxFULLSCREEN_NOMENUBAR);
    CustomDialog *RPGselect = new CustomDialog(CharCreatorSelection,wxT("RPG Selection"),wxSize(g_sizex/2,g_sizey/2));
    RPGselect->Show(true);
}
Character creation wizard created from Dialog

Code: Select all

void CustomDialog::OnDone(wxCommandEvent&event)
{
int RPGdone = RPGradio->GetSelection();
int Chardone = Charradio->GetSelection();
int numdone=numradio->GetSelection();
Destroy();[b][u]//problem[/u][/b]
wxFrame *CharCreator =new wxFrame(NULL,-1,"",wxPoint(0,0),g_mainmenusize,wxFULLSCREEN_NOMENUBAR);
if (RPGdone==0&&Chardone==0){
    PWitcher *PWitcherCreator=new PWitcher(CharCreator);
    PWitcherCreator->RunWizard(PWitcherCreator->GetFirstPage());
}
}

I have tried instead to use

Code: Select all

Close(TRUE);
this->Close(True);
instead but that causes the mentioned problem.
Last edited by doublemax on Fri Oct 15, 2021 10:19 pm, edited 2 times in total.
Reason: Added code tags
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWizard closing entire app on finish

Post by doublemax »

Code: Select all

void MainFrame::OnNewChar(wxCommandEvent&event)
{
    wxFrame *CharCreatorSelection =new wxFrame(NULL,-1,"",wxPoint(0,0),g_mainmenusize,wxFULLSCREEN_NOMENUBAR);
    CustomDialog *RPGselect = new CustomDialog(CharCreatorSelection,wxT("RPG Selection"),wxSize(g_sizex/2,g_sizey/2));
    RPGselect->Show(true);
}
Why are you creating a new frame here?

And if CustomDialog derives from wxDialog, it should be created on the stack and shown with ShowModal().
Use the source, Luke!
Elured42
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Oct 15, 2021 2:58 am

Re: wxWizard closing entire app on finish

Post by Elured42 »

Because the same problem occurred when I originally used the Main menu as the parent window using
this->GetParentForModialDialog()
and attempted to see if using a different window would do anything different.
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWizard closing entire app on finish

Post by doublemax »

First of all, get rid of the dummy-frame creations everywhere.

A modal dialog should be shown with ShowModal(). Inside the dialog, use EndModal() to end it.

I think the general structure should look something like this:

Code: Select all

void MainFrame::OnNewChar(wxCommandEvent&event)
{
    CustomDialog RPGselect(this, wxT("RPG Selection"),wxSize(g_sizex/2,g_sizey/2));
    if(RPGselect.ShowModal() == wxID_OK)
    {
        PWitcher PWitcherCreator(this);
        PWitcherCreator.RunWizard(PWitcherCreator.GetFirstPage());
    }
}

Code: Select all

void CustomDialog::OnDone(wxCommandEvent&event)
{
  int RPGdone = RPGradio->GetSelection();
  int Chardone = Charradio->GetSelection();
  int numdone = numradio->GetSelection();
  if (RPGdone == 0 && Chardone == 0) {
    EndModal(wxID_OK);
  } else {
    EndModal(wxID_CANCEL);
  }
}
Use the source, Luke!
Elured42
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Oct 15, 2021 2:58 am

Re: wxWizard closing entire app on finish

Post by Elured42 »

Thank you for helping a newbie who somehow missed that EndModal() was a thing.

Finished code based on help

void CustomDialog::OnDone(wxCommandEvent&event)
{
int RPGdone = RPGradio->GetSelection();
int Chardone = Charradio->GetSelection();
int numdone=numradio->GetSelection();
if (RPGdone==0&&Chardone==0){
PWitcher PWitcherCreator(this);
PWitcherCreator.RunWizard(PWitcherCreator.GetFirstPage());
}
EndModal(wxID_OK);
}

void MainFrame::OnNewChar(wxCommandEvent&event)
{
CustomDialog RPGselection(this, wxT("RPG Selection"),wxSize(g_sizex/2,g_sizey/2));
}
Post Reply