在 wxWidgets 中关闭框架的正确方法是什么
What is the right way to close a frame in wxWidgets
我创建了一个应用程序,它有一个继承自 wxFrame 的 ShellFromFBFrame window。
App对象定义如下:
bool ShellFromFBApp::OnInit()
{
//(*AppInitialize
bool wxsOK = true;
wxInitAllImageHandlers();
if ( wxsOK )
{
ShellFromFBFrame* Frame = new ShellFromFBFrame(0);
Frame->Show();
}
//*)
return wxsOK;
}
The ShellFromFBFrame is as follows:
ShellFromFBFrame::ShellFromFBFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(ShellFromFBFrame)
wxBoxSizer* MainSizer;
wxBoxSizer* mainContentSizer;
wxMenu* createContact;
...
the ShellFromFBFrame opens a new CreateContactFrame:
void ShellFromFBFrame::OnCreateContact(wxCommandEvent& event)
{
CreateContactFrame* createContactFrame = new CreateContactFrame(NULL,wxID_ANY);
createContactFrame->Show(true);
}
The CreateContactFrame is as follows:
CreateContactFrame::CreateContactFrame(wxWindow* parent,wxWindowID id)
{
//ctor
Create(parent, id, wxT("Create Contact"), wxDefaultPosition, wxSize(1100,700), wxDEFAULT_FRAME_STYLE, _T("id"));
// int num;
// num = wxAtoi(row);
//this->rowToFetch = row;
...
BEGIN_EVENT_TABLE(CreateContactFrame, wxFrame)
EVT_BUTTON(ID_CREATEBTN, CreateContactFrame::CreateContact)
END_EVENT_TABLE()
但是当我通过关闭按钮或取消按钮关闭 CreateContactFrame window 时。我的应用程序崩溃,我在构建日志中收到以下进程终止错误消息:
Process terminated with status -1073740940 (0 minute(s), 12 second(s))
我做错了什么?
由于无限递归,您 运行 陷入堆栈溢出(多么有主题!):您的 wxEVT_CLOSE
处理程序调用 Close()
导致另一个 wxEVT_CLOSE
正在生成等等。如果您无事可做,只需完全删除处理程序即可解决问题。
此外,当遇到可重现的崩溃时,首先要做的是使用调试信息构建程序,运行 在调试器下,查看崩溃时的堆栈 -- 在 90 % cases 这将为您提供答案,当您在堆栈中看到对 OnClose()
的无休止重复调用时,肯定会出现这种情况。
这不是编码问题,而是 wxwidgets 库的构建问题。适用于 MSVC 2019。
我创建了一个应用程序,它有一个继承自 wxFrame 的 ShellFromFBFrame window。
App对象定义如下:
bool ShellFromFBApp::OnInit()
{
//(*AppInitialize
bool wxsOK = true;
wxInitAllImageHandlers();
if ( wxsOK )
{
ShellFromFBFrame* Frame = new ShellFromFBFrame(0);
Frame->Show();
}
//*)
return wxsOK;
}
The ShellFromFBFrame is as follows:
ShellFromFBFrame::ShellFromFBFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(ShellFromFBFrame)
wxBoxSizer* MainSizer;
wxBoxSizer* mainContentSizer;
wxMenu* createContact;
...
the ShellFromFBFrame opens a new CreateContactFrame:
void ShellFromFBFrame::OnCreateContact(wxCommandEvent& event)
{
CreateContactFrame* createContactFrame = new CreateContactFrame(NULL,wxID_ANY);
createContactFrame->Show(true);
}
The CreateContactFrame is as follows:
CreateContactFrame::CreateContactFrame(wxWindow* parent,wxWindowID id)
{
//ctor
Create(parent, id, wxT("Create Contact"), wxDefaultPosition, wxSize(1100,700), wxDEFAULT_FRAME_STYLE, _T("id"));
// int num;
// num = wxAtoi(row);
//this->rowToFetch = row;
...
BEGIN_EVENT_TABLE(CreateContactFrame, wxFrame)
EVT_BUTTON(ID_CREATEBTN, CreateContactFrame::CreateContact)
END_EVENT_TABLE()
但是当我通过关闭按钮或取消按钮关闭 CreateContactFrame window 时。我的应用程序崩溃,我在构建日志中收到以下进程终止错误消息:
Process terminated with status -1073740940 (0 minute(s), 12 second(s))
我做错了什么?
由于无限递归,您 运行 陷入堆栈溢出(多么有主题!):您的 wxEVT_CLOSE
处理程序调用 Close()
导致另一个 wxEVT_CLOSE
正在生成等等。如果您无事可做,只需完全删除处理程序即可解决问题。
此外,当遇到可重现的崩溃时,首先要做的是使用调试信息构建程序,运行 在调试器下,查看崩溃时的堆栈 -- 在 90 % cases 这将为您提供答案,当您在堆栈中看到对 OnClose()
的无休止重复调用时,肯定会出现这种情况。
这不是编码问题,而是 wxwidgets 库的构建问题。适用于 MSVC 2019。