【发布时间】:2015-01-05 06:22:15
【问题描述】:
我的 wxApp 派生类在调用 OnInit 之前调用了它的析构函数。我想我找到了错误似乎上升的地方。在文件 appcmn.cpp 中,在方法 wxAppBase::Initialize 中,OnInitGui 返回 false。这似乎是由于函数返回了一个空的顶级窗口。不过,我不知道这是否真的是问题所在,无论发生什么,我都有些不知所措。
- 操作系统:Windows 7 家庭 64 位
- 编译器:来自 Visual Studio 2013 Express 的 cl 64bit
- wxWidgets 版本:3.0.2
我使用 wxWidgets 下载中包含的 Visual Studio 2013 Express 解决方案来构建 64 位调试 wxWidgets 库。
这是我的代码。
VoidCrafterApp.h
#ifndef VOIDCRAFTERAPP_H
#define VOIDCRAFTERAPP_H
#include "wx/wx.h"
class MainFrame;
class VoidCrafterApp : public wxApp
{
MainFrame* m_pMainframe;
public:
~VoidCrafterApp();
virtual bool OnInit();
};
DECLARE_APP(VoidCrafterApp);
#endif
VoidCrafterApp.cpp
#include "VoidCrafterApp.h"
#include "MainFrame.h"
IMPLEMENT_APP(VoidCrafterApp);
VoidCrafterApp::~VoidCrafterApp()
{
bool wegothere = true; // This statement is executed
}
bool VoidCrafterApp::OnInit()
{
m_pMainframe = new MainFrame("Hello World", wxPoint(50, 50), wxSize(450, 340));
m_pMainframe->Show( true );
return true;
}
MainFrame.h
#ifndef MAINFRAME_H
#define MAINFRAME_H
#include "wx/frame.h"
#include "wx/menu.h"
enum
{
ID_Hello = 1
};
class MainFrame : public wxFrame
{
// Top Menu Bar
wxMenuBar* m_pMenuBar;
public:
MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
};
#endif
MainFrame.cpp
#include "MainFrame.h"
#include "wx/wx.h"
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(ID_Hello, MainFrame::OnHello)
EVT_MENU(wxID_EXIT, MainFrame::OnExit)
EVT_MENU(wxID_ABOUT, MainFrame::OnAbout)
wxEND_EVENT_TABLE()
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
// Create the top menus
wxMenu* pMenuFile = new wxMenu();
pMenuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item");
pMenuFile->AppendSeparator();
pMenuFile->Append(wxID_EXIT);
wxMenu* pMenuHelp = new wxMenu();
pMenuHelp->Append(wxID_ABOUT);
wxMenuBar *m_pMenuBar = new wxMenuBar;
m_pMenuBar->Append(pMenuFile, "&File");
m_pMenuBar->Append(pMenuHelp, "&Help");
SetMenuBar(m_pMenuBar);
CreateStatusBar();
SetStatusText("Welcome to wxWidgets!");
}
void MainFrame::OnHello(wxCommandEvent& event)
{
wxLogMessage("Hello world from wxWidgets!");
}
void MainFrame::OnExit(wxCommandEvent& event)
{
Close(false);
}
void MainFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("This is a wxWidgets' Hello world sample",
"About Hello World", wxOK | wxICON_INFORMATION);
}
【问题讨论】: