【发布时间】:2015-01-16 19:50:37
【问题描述】:
标题: 我有一个带有 testfunction 和一个面板的课程
class testsubclass{
public:
testsubclass();
void testfunc(wxCommandEvent &event);
};
class panelonwindow : public wxPanel{
public:
panelonwindow(wxWindow *windowid, int ID);
wxWindow *mywindow, *mypanel;
wxTextCtrl *mytextcontrol;
void maketextctrl(std::string label, int &id);
}
我希望班级在我的主窗口上创建一个 Textcontrol。作为我使用的功能
testsubclass::testsubclass(){
}
panelonwindow::panelonwindow(wxWindow *windowid, int ID)
:wxPanel(windowid, ID, wxDefaultPosition, wxSize(150, 150)){
mywindow = windowid;
mypanel = this;
};
void panelonwindow::maketextctrl(std::string label, int &id){
wxString newlabel(label.c_str(), wxConvUTF8);
mytextcontrol = new wxTextCtrl(mypanel, id, newlabel, wxDefaultPosition, wxSize(130, 30));
}
void testsubclass::testfunc(wxCommandEvent &event){
printf("%s\n", "testfunc was called");
}
我的主窗口头文件包含指向这两个类的指针:
标题:
wxWindow *mainwindow;
testsubclass *mysubclass;
panelonwindow *testpanel;
int ID1 = 100;
int ID2 = 101;
现在主函数如下所示:
mainwindow = this;
std::string textcontrolstring = "this is a test";
testpanel = new panelonwindow(mainwindow, ID);
testpanel->maketextctrl(textcontrolstring, ID2);
mysubclass = new testsubclass();
问题是,我无法从主窗口函数将 testsublass 函数 testfunc 链接到这样的事件,当我尝试执行以下操作时,我收到了一些神秘的编译器消息:
Connect(ID2, wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(mysubclass->testfunc));
我可以将 void panelonwindow::maketextctrl 中的事件链接到 panelonwindow 函数的另一个成员(前提是我以 void panelonwindow::testfunc(wxCommandEvent &event) 之类的方式声明它们)
void panelonwindow::maketextctrl(std::string label, int &id){
wxString newlabel(label.c_str(), wxConvUTF8);
mytextcontrol = new wxTextCtrl(mypanel, id, newlabel, wxDefaultPosition, wxSize(130, 30));
Connect(id, wxEVT_COMMAND_TEXT_UPDATED,
CommandEventHandler(panelonwindow::testfunc))
}
由于我计划在面板上创建大量按钮,因此我更愿意在成员类中定义函数,而不是为每个按钮/文本控件窗口编写一个函数,分别控制所有窗口。
这可能是一个新手问题,但我将不胜感激任何形式的帮助
【问题讨论】: