wxWidgets: 不能从 wxListCtrl 继承
wxWidgets: can't inherit from wxListCtrl
我在以下代码中有一个冻结问题:( ebcframe是继承的类(wxframe)。查找" else"部分,谢谢)
)void EBCFrame::OnOpen(wxCommandEvent& event)
{
int error = 0;
_window = new wxScrolledWindow(this, wxID_ANY, wxPoint(0, 0), wxSize(600, 400), wxVSCROLL|wxHSCROLL);
wxFileDialog* fileDialog = new wxFileDialog(this, wxT("Select a file"), wxEmptyString, wxEmptyString, wxT("Event Bus configuration file (*.ebf)|*.ebf|Txt|*.txt|All|*"));
if(fileDialog->ShowModal() == wxID_OK)
{
//taking the file's name we want to process
wxString tempfilename;
tempfilename += fileDialog->GetPath();
//need to convert to const char*
char* filename = new char[tempfilename.length()];
strncpy(filename, (const char*)tempfilename.mb_str(wxConvUTF8), tempfilename.length() - 1);
//done
_handler->Read(filename);
//processing it
error = _handler->GetError();
if(error != 0) //an error has occoured
{
wxMessageDialog dialog( NULL, wxT("An error has occoured: " + wxString::FromAscii(strerror(error))), wxT("Error"), wxOK|wxICON_ERROR);
dialog.ShowModal();
}
else
{
// Create a list in report mode
EBCList* list = new EBCList();
// it works instead
//wxListCtrl* list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(400, 400),wxLC_REPORT|wxLC_SINGLE_SEL);
// even if I delete the following code, and I leave only the first code line in the else section, it still freezes
// Insert two columns
wxListItem itemCol;
itemCol.SetText(wxT("Param"));
itemCol.SetImage(-1);
itemCol.SetAlign(wxLIST_FORMAT_CENTRE);
list->InsertColumn(0, itemCol);
list->SetColumnWidth(0, wxLIST_AUTOSIZE );
itemCol.SetText(wxT("Value"));
itemCol.SetAlign(wxLIST_FORMAT_CENTRE);
list->InsertColumn(1, itemCol);
list->SetColumnWidth(1, wxLIST_AUTOSIZE );
// Insert ten items
for ( int i = 0; i < 5; i++ )
{
wxString buf;
// Insert an item, with a string for column 0,
buf.Printf(wxString::FromAscii(_handler->GetAttributeName(i + 1).c_str()), i);
list->InsertItem(i, buf);
// The item may change position due to e.g. sorting,
// so store the original index in the item’s data
list->SetItemData(i, i);
// Set a string for column 1
buf.Printf(wxString::FromAscii(_handler->GetAttribute(i + 1).c_str()), i);
list->SetItem(i, 1, buf);
}
}
_window->Show(true);
}
}
这是EBCLIST类的标题和CPP文件。标题:
#ifndef EBCLIST_H
#define EBCLIST_H
#include <wx/listctrl.h>
#include <wx/menu.h>
enum LIST_ENUM
{
wxLIST_CTRL = 1000,
wxLIST_CTRL_EDIT
};
class EBCList : public wxListCtrl
{
public:
EBCList();
~EBCList();
void OnActivated(wxListEvent& event);
void OnRightClick(wxMouseEvent& event);
private:
// This class handles events
DECLARE_EVENT_TABLE()
};
#endif // EBCLIST_H
cpp:
#include "EBCList.h"
EBCList::EBCList() : wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(400, 400),wxLC_REPORT|wxLC_SINGLE_SEL)
{
}
EBCList::~EBCList()
{
}
void EBCList::OnActivated(wxListEvent& event)
{
}
void EBCList::OnRightClick(wxMouseEvent& event)
{
int flags;
long subitem; /* used by HitTest */
long key = HitTest(event.GetPosition(), flags, &subitem);
wxMenu menu;
wxPoint pos;
pos = event.GetPosition();
menu.Append(wxLIST_CTRL_EDIT, _T("&Edit"));
PopupMenu(&menu, pos.x, pos.y);
}
BEGIN_EVENT_TABLE(EBCList, wxListCtrl)
EVT_LIST_ITEM_ACTIVATED(wxLIST_CTRL, EBCList::OnActivated)
EVT_RIGHT_DOWN(EBCList::OnRightClick)
END_EVENT_TABLE()
我无法理解为什么该程序会冻结,因为我声明EBCLIST的构建器的方式基本上就像WXLISTCTRL Coftructor的"短期发动"。任何帮助都将受到赞赏。谢谢您的支持
您正在向wxlistctrl喂食构造函数中的父窗口的指针:
EBCList::EBCList() : wxListCtrl(this, ...
// ^^^^
尝试:
EBCList::EBCList(wxWindow* parent) : wxListCtrl(parent, ...
并将其创建为:
EBCList* list = new EBCList(this); // EBCFrame as parent
相关文章:
- 继承函数的重载解析
- 继承期间显示未知行为的子类
- 头文件-继承c++
- 为什么在保护模式下继承升级不起作用
- 通过继承类使用来自不同命名空间的运算符
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 混合组合和继承的C++问题
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 从类继承时,继承的类是否会通过父类重新定义继承的变量
- 公共与私人继承
- 如何创建从同一类继承的不同对象的向量
- 如何从另一个文件继承私有成员变量和公共函数
- 在模板基类中为继承类中的可选重写生成虚拟方法
- 带有继承的C++工厂
- 我应该避免多重实现继承吗
- C++继承更改成员
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 关于C++中具有多重继承"this"指针的说明
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- wxWidgets: 不能从 wxListCtrl 继承