在给窗体加OnClose()事件处理,添加Close();或Destroy();代码后,如:
void NewDialog::OnClose(wxCloseEvent& event)
{
Close();
//event.Skip();
// Destroy();
}
调试运行的时候会收到崩溃信息;
若替换为使用event.Skip(true);采用默认处理不会出现此问题,但是如果是使用的单实例程序,并且在App中的OnInit()函数返回true
『程序继续运行,没有关闭』时,所有窗体关闭程序退出后,实际的进程并没有结束,通过
ps -A命令可以查看到进程的相关信息,若想再次运行程序,必须使用
kill pid命令结束当前进程。
『若是在Debug环境下不会出现这个问题,因为关闭窗体后,调试器并没有退出,通过结束调试可以终止当前进程』
若想解决这个问题,可以在OnClose()中使用Close();或Destroy();但是调试过程中会产生这个Program received signal SIGABRT, Aborted.
In __kernel_vsyscall () ()错误,不过直接运行程序就不会出现退出程序时进程没有结束的问题,我也用过
unsigned long IdProcess = wxGetProcessId();
wxKill(IdProcess);
结束进程的命令,但是调试时也会崩溃。------------OnInit()中返回false不会存在这个问题,返回即程序退出。
单实例程序:在App.h中添加
#include <wx/snglinst.h>
class TestAppExitApp : public wxApp
{
public:
TestAppExitApp();
virtual bool OnInit();
private:
wxSingleInstanceChecker instance_checker;
};
.cpp
TestAppExitApp::TestAppExitApp()
:instance_checker(_T("my_app_name"))
{
}
bool TestAppExitApp::OnInit()
{
if (instance_checker.IsAnotherRunning())
{
wxLogError(_T("Errot 11"));
return false;
}
//(*AppInitialize
bool wxsOK = true;
wxInitAllImageHandlers();
wxXmlResource::Get()->InitAllHandlers();
wxsOK = wxsOK && wxXmlResource::Get()->Load(_T("NewDialog.xrc"));
if ( wxsOK )
{
NewDialog Dlg(0);
// TestAppExitDialog Dlg(0);
SetTopWindow(&Dlg);
Dlg.ShowModal();
// wxsOK = false;
}
//*)
return wxsOK;
}
单实例没有采用创建单实例对象并在OnExit()删除对象的做法,代码如下,是因为在调试的过程中没有调用OnExit函数,程序退出再运行时会有文件信息错误的提示,这么做就可以解决这个问题。
bool MyApp::OnInit(){ const wxString name = wxString::Format("MyApp-%s", wxGetUserId().c_str()); m_checker = new wxSingleInstanceChecker(name); if ( m_checker->IsAnotherRunning() ) { wxLogError(_("Another program instance is already running, aborting.")); return false; } ... more initializations ... return true;}int MyApp::OnExit(){ delete m_checker; return 0;}
这个问题只能先放在这里了,希望后续的学习过程中能够完美的解决。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。