Problem with tabs Events Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
BinaryShinigami
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Sep 04, 2008 1:51 am

Problem with tabs Events

Post by BinaryShinigami »

Hey I'm trying to make a simple GUI with tabs that handle thier own events, I have made a class that will represent each tab and all its controls, the controls are then added to a panel member of that class and then the panel is added to the notebook, to handle events I'm using connect to add a function that is a member of the class that I made to the panels events, I have tested it and it works, when I click a button I get a message box popping up So I know it works, The problem is, If i try to access a variable of the class I made in the event handler function it will compile but there will be a run time error. I have made the members public that I which to access and tried everything I can but for some reason it won't work. Here is basically what I have.

class.h

Code: Select all

class myTabClass : public wxEvtHandler
{
public:
  myTabClass(wxWindow *notebook);
  ~myTabClass();
  wxButton *testBtn;
  void btnFunction(wxCommandEvent &event);
  wxPanel *panel;
  int numToIterate;
  wxWindowID id;
};
class.cpp

Code: Select all

myTabClass::myTabClass(wxWindow *notebook)
{
  id = 4001;
  panel = new panel(notebook);
  testBtn = new wxButton(panel,id,wxT("test"));
     panel->Connect(id,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(myTabClass::btnFunction));
numToIterate = 1;
}

void myTabClass::btnFunction(wxCommandEvent &event)
{
 this->numToIterate++;
}

myTabClass::~myTabClass()
{

}

What the problem seems to be is that when its tries to access numToIterator to add to it, it can't find it, I'm not sure how I can solve this problem so that it works. Any help would be great. Thanks in advanced.[/code]
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Hi,

you need to pass an event sink parameter to Connect.
BinaryShinigami
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Sep 04, 2008 1:51 am

Post by BinaryShinigami »

Thank you, that was what was wrong thanks very much, maybe you could clear something up for me, I passed this as the sink but in the documentation it said that if I didn't pass anything to it that it would use this by default yet it didn't, is it maybe just a flaw with the documentation or possibly just I have the wrong documentation?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

BinaryShinigami wrote:Thank you, that was what was wrong thanks very much, maybe you could clear something up for me, I passed this as the sink but in the documentation it said that if I didn't pass anything to it that it would use this by default yet it didn't, is it maybe just a flaw with the documentation or possibly just I have the wrong documentation?
Hi,

the "this" they refer to is the this inside the Connect method when it's executed; since the call is panel->Connect, inside Connect(), "this" will be "panel".
BinaryShinigami
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Sep 04, 2008 1:51 am

Post by BinaryShinigami »

That's good to know, thanks man that helped alot now it works like a charm.
Post Reply