wxWidgets hello world tutorial表現出奇怪的行爲。當我添加使用以下行MyFrame構造一個面板到應用程序:當wxPanel添加時輸入關閉wxWidgets應用程序
wxPanel *panel = new wxPanel(this);
的[返回]和[鍵盤輸入]鍵導致程序退出(清潔檢測關閉事件)。
這是爲什麼?沒有wxPanel,鍵盤什麼也不做。
下面是與添加的行代碼:
// hworld.cpp
// Version using dynamic event routing
#include <wx/wx.h>
class MyApp : public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
};
enum
{
ID_Quit=1,
ID_About
};
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_("Hello World"), wxPoint(50, 50),
wxSize(450, 350));
frame->Connect(ID_Quit, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) &MyFrame::OnQuit);
frame->Connect(ID_About, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) &MyFrame::OnAbout);
frame->Show(true);
SetTopWindow(frame);
return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, -1, title, pos, size)
{
wxMenuBar *menuBar = new wxMenuBar;
wxMenu *menuFile = new wxMenu;
menuFile->Append(ID_About, _("&About..."));
menuFile->AppendSeparator();
menuFile->Append(ID_Quit, _("E&xit"));
menuBar->Append(menuFile, _("&File"));
// Added line causing failure.
wxPanel *panel = new wxPanel(this);
SetMenuBar(menuBar);
CreateStatusBar();
SetStatusText(_("Welcome to wxWidgets!"));
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(_("wxWidgets Hello World example."),
_("About Hello World"),
wxOK|wxICON_INFORMATION, this);
}
你描述的行爲在這裏是不可重複的(當然,這是意想不到的,不應該發生)。你使用哪個平臺和版本的wxWidgets? –
這在Windows 7的2.9版本中發生。我將更新到2.9.5並查看是否可以解決此問題。 –