Cloning wxEvtHandler from a costum class Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
the_drow
Experienced Solver
Experienced Solver
Posts: 67
Joined: Fri Sep 15, 2006 6:20 am

Cloning wxEvtHandler from a costum class

Post by the_drow »

I have a problem with copying a wxEvtHandler instance.

I have this class:

Code: Select all

class A : public wxEvtHandler
{
  B obj;
public:
  A() {
        obj.handler = this;
      }
//...
};

class B
{
   B()
   {
      //raises event
   }
};
This code crashes for some reason.
Any ideas?
frank_frl
Earned some good credits
Earned some good credits
Posts: 139
Joined: Sat Feb 18, 2006 1:41 pm
Location: Germany

Post by frank_frl »

Hi the_drow,

you are using a member 'handler' of class B in the ctor of class A, but this member is not declared in class B.

Code: Select all

class A : public wxEvtHandler
{
  B obj;
public:
  A() {
        obj.handler = this;
      }
//...
};

class B
{
   B()
   {
      //raises event
   }
};
Regards

Frank
the_drow
Experienced Solver
Experienced Solver
Posts: 67
Joined: Fri Sep 15, 2006 6:20 am

Post by the_drow »

frank_frl wrote:Hi the_drow,

you are using a member 'handler' of class B in the ctor of class A, but this member is not declared in class B.

Code: Select all

class A : public wxEvtHandler
{
  B obj;
public:
  A() {
        obj.handler = this;
      }
//...
};

class B
{
   B()
   {
      //raises event
   }
};
Regards

Frank
oh you're being petty lol. I did declare it in my code.
The program crashes on runtime.
stef
Knows some wx things
Knows some wx things
Posts: 48
Joined: Mon Feb 06, 2006 11:44 am

Re: Cloning wxEvtHandler from a costum class

Post by stef »

the_drow wrote:I have a problem with copying a wxEvtHandler instance.

I have this class:

Code: Select all

class A : public wxEvtHandler
{
  B obj;
public:
  A() {
        obj.handler = this;
      }
//...
};

class B
{
   B()
   {
      //raises event
   }
};
This code crashes for some reason.
Any ideas?
The problem is that the construction of object "obj" inside class A happens before the handler is assigned.

There are a couple of possibilities:
- don't raise the event in the B constructor (but sometimes later)
- set B's handler to a default handler initially
- allocate the B object on the heap with the handler as an argument.

and probably more
the_drow
Experienced Solver
Experienced Solver
Posts: 67
Joined: Fri Sep 15, 2006 6:20 am

Re: Cloning wxEvtHandler from a costum class

Post by the_drow »

stef wrote:
the_drow wrote:I have a problem with copying a wxEvtHandler instance.

I have this class:

Code: Select all

class A : public wxEvtHandler
{
  B obj;
public:
  A() {
        obj.handler = this;
      }
//...
};

class B
{
   B()
   {
      //raises event
   }
};
This code crashes for some reason.
Any ideas?
The problem is that the construction of object "obj" inside class A happens before the handler is assigned.

There are a couple of possibilities:
- don't raise the event in the B constructor (but sometimes later)
- set B's handler to a default handler initially
- allocate the B object on the heap with the handler as an argument.

and probably more
I moved it from the constructor and now it just doesn't raise the event.

EDIT:
I used AddPendingEvent instead of ProcessEvent and that caused the problem.
Post Reply