gpt4 book ai didi

c++ - wxWidgets 关闭时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:53:11 26 4
gpt4 key购买 nike

我的文件看起来像这样:

主要.cpp

...
bool SyncApp::OnInit(){
SetTopWindow(new syncWindow(_("(S)FTP Automatic Sync")));
GetTopWindow()->Show(true);
return true;
}
...

同步窗口.h

#include <wx/wx.h>

class syncWindow : public wxFrame {
public:
syncWindow(wxString title) : wxFrame(NULL, -1, title) { initialize(); }
private:
void initialize();
wxTextCtrl * serverEntry;
};

同步窗口.cpp

void syncWindow::initialize(){
serverEntry = new wxTextCtrl(this, wxID_ANY);

this->AddChild(serverEntry);
}

无论出于何种原因,每当我关闭窗口时都会出现段错误。如果我不将 serverEntry 作为子项添加到窗口,我就不会出现段错误。我不明白为什么要这样做。我在 CentOS 6、g++ 4.7 和 wxGTK 2.8 上。有没有人知道或暗示为什么会发生这种情况?

最佳答案

由于您在构造子窗口时指定了父窗口,因此链接已经存在并且调用 this->AddChild(serverEntry); 将在您关闭窗口时导致双重释放或类似错误。 http://docs.wxwidgets.org/2.8/wx_wxwindow.html#wxwindowaddchild

wxWindow::AddChild

Adds a child window. This is called automatically by window creation functions so should not be required by the application programmer.

Notice that this function is mostly internal to wxWidgets and shouldn't be called by the user code.

关于c++ - wxWidgets 关闭时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17255741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com