[sigc] Crash when deleting itself in a signal emission...



Hello all,

i am doing something bad like:

Class::Class ()
{
	mMySignal.connect (mem_fun (*this, Class::handlerOfTheSignal));
}

void Class::method ()
{
	mMySignal->emit (this);
}


void Class::handlerOfTheSignal (Class* p)
{
.......
	delete p;// Or delete this :-)
........
}

And basically i get a crash in the destroying of the ~signal() which is member of the Class class.

Any hint on how to circumvent this problem? I could for example prevent the error by not using signal emitting, but instead doing something like:

Class::Class ()
{
	mMySignal.connect (mem_fun (*this, Class::handlerOfTheSignal));
}

void Class::method ()
{
	mMySignal->emit (this);
	delete this;
}


void Class::handlerOfTheSignal ()
{
.......
	do some business......
........
}

but still havent tryed, but still should work. Any suggestion on the topic? Notice that i really need to use to emit the signal because there are some other classes (i.e. instances) who want to receive the notification of that event.

Thanks for any suggestion,
Luca



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]