wxWidgets 在调用 wxApp::OnInit 之前退出
wxWidgets exits before wxApp::OnInit is invoked
我的wxApp派生类在调用其OnInit之前调用了其析构函数。我想我追踪到了错误似乎上升的地方。在文件 appcmn.cpp 中,在方法 wxAppBase::Initialize 中,OnInitGui 返回 false。这似乎是由于函数返回一个空的顶级窗口。我不知道这是否真的是问题所在,无论哪种方式,我都对正在发生的事情一无所知。
- 操作系统: 视窗 7 家庭 64 位
- 编译器:来自Visual Studio 2013 Express的cl 64位
- wx小部件版本: 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
虚空工匠应用程序.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;
}
大型机.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
大型机.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);
}
OnInitGui()
在wxMSW中总是返回true,除非被覆盖,并且您似乎没有覆盖它,因此看起来您可能有某种糟糕的构建,调用了错误的虚拟函数(如果您使用较新版本的标头和较旧的库或类似的东西,则可能会发生这种情况)。所以我的建议是从头开始重建所有内容,即库和应用程序,看看它是否能解决问题。
如果没有,请考虑运行与您的程序非常相似的最小示例。如果它不起作用,问题肯定出在构建上。如果是这样,那么,通过将其与代码之间的差异一分为二,您应该能够快速找到导致程序失败的关键更改。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 如何让LLDB在成功时退出,在失败时等待
- C++控制台应用程序阻止退出
- 程序在执行程序的其余部分之前退出
- 构造函数在退出函数时无法初始化一个参数
- 为什么异常不退出程序?
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 退出简单while循环时出现问题
- 使用vscode调试时,GDB意外退出
- pclose() 不会给我进程退出代码
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++从另一个函数退出函数
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- C++逗号分隔的输入数组代码过早退出
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 为什么 C++ 中的以下结构声明会导致退出 127?
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- wxWidgets 在调用 wxApp::OnInit 之前退出