【发布时间】:2014-05-13 13:38:43
【问题描述】:
我正在尝试使用 wxTextCtrl 为我的 GUI 应用程序创建一个输入框。 我已经制作了这个盒子,但是当我试图从中获取输入文本时,它崩溃了,我不知道为什么。
代码如下:
main.cpp:
int main(int argc, char** argv)
{
wxApp::SetInstance( new App() );
wxEntryStart(argc, argv);
wxTheApp->OnInit();
wxTheApp->OnRun();
wxTheApp->OnExit();
wxEntryCleanup();
return 0;
}
app.cpp:
bool App::OnInit()
{
wxString title = "Version: ";
title += APP_VERSION;
/* Create the frame for my app */
Frame *simple = new Frame(0, wxID_ANY, title, wxDefaultPosition, wxSize(287, 700)/*wxSize(287, 450)*/, (wxDEFAULT_FRAME_STYLE & ~(wxRESIZE_BORDER | wxMAXIMIZE_BOX)));
simple->Show(true);
return true;
}
frame.cpp:
Frame::Frame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
: wxFrame( parent, id, title, pos, size, style )
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
input_text = new wxTextCtrl(this, wxID_ANY, "initial", wxPoint(10, 400), wxSize(250, 100));
wxString str = input_text->GetValue();
wxMessageBox(str);
}
它在 frame.cpp 上崩溃了:wxString str = input_text->GetValue();
我正在使用 wxWidgets-3.0.0 和 Visual Studio 2012 在 Windows 上进行编译。
这可能是一件非常简单的事情,但我刚开始使用 wxWidgets 并没有太多经验。
谢谢。
【问题讨论】: