wxDialog works fine but a wxFileDialog call results in program not terminating
Similar problem to last time. I run the code, exit it. The GUI disappears and it appears to have been fully exited but I check my process list and the code is there still holding memory.
I've narrowed it down to a call to wxFileDialog. I don't understand what I'm doing wrong because I'm calling much in a similar way as I'm calling a wxDialog. The wxDialog call doesn't result in this problem but the wxFileDialog does cause it.
Works fine:
// Help Dialog
void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
{
wxBoxSizer *topsizer;
wxHtmlWindow *html;
wxDialog dlg(this, wxID_ANY, wxString(_("Help")));
topsizer = new wxBoxSizer(wxVERTICAL);
html = new wxHtmlWindow(&dlg, wxID_ANY, wxDefaultPosition,
wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
html->SetBorders(0);
html->LoadPage(wxT("data/help.html"));
// Fit the HTML window to the size of its contents
html->SetSize(html->GetInternalRepresentation()->GetWidth(),
html->GetInternalRepresentation()->GetHeight());
topsizer->Add(html, 1, wxALL, 10);
wxButton *but = new wxButton(&dlg, wxID_OK, _("OK"));
but->SetDefault();
topsizer->Add(but, 0, wxALL | wxALIGN_RIGHT, 15);
dlg.SetSizer(topsizer);
topsizer->Fit(&dlg);
dlg.CentreOnParent();
dlg.ShowModal();
}
Causes problem:
void MyFrame::OnVidFile(wxCommandEvent& WXUNUSED(event))
{
wxString caption = wxT("Choose a file");
wxString wildcard = wxT("AVI files (*.avi)|*.avi");
wxString defaultDir = wxGetHo开发者_C百科meDir();
wxString defaultFilename = wxEmptyString;
wxFileDialog dialog(this, caption, defaultDir, defaultFilename, wildcard, wxOPEN | wxFILE_MUST_EXIST );
dialog.CentreOnParent();
if(dialog.ShowModal() == wxID_OK) // problem
pathVid = dialog.GetPath().c_str();
}
This results in the program not terminating correctly even if I throw in a dialog.Destroy(); or dialog.Close(); at the end. They look like similar calls to the dialog class to me?
Am I missing something here?
Problem is a conflict with OpenCV (specifically HighGUI).
To avoid this problem and the OLE error problem, override the WxWidgets initialize base class virtual as follows:
bool MywxApp::Initialize( int& argc, wxChar **argv )
{
::CoUninitialize();
return wxApp::Initialize( argc, argv );
}
精彩评论