Re: [gtkmm] Slots from non-Gtk subclasses.

Am 2003.02.24 07:25 schrieb(en) Andrew E. Makeev:

I have a class that isn't derived from any Gtk classes.  It does,
however, have member functions that will pop up Gtk windows, and
member functions that will handle callbacks from those windows.

The problem is that the "SigC::slot(class, &member)" function seems
to require a class who's derived from Gtk.  I can't get the class to
compile unless I force my class to be a subclass of a Gtk class.

class Foo : public SigC::Object { ... }


class Foo : virtual public SigC::Object { ... };

Why this solution was not mentioned yet?
There is a way to connect method of a class that is not derived from SigC::Object. I've read something about "use it on your own risk" earlier, but haven't met any problem with it for now.

#include <sigc++/class_slot.h>


<SIGNAL>.connect (SigC::slot_class(<MyClass>, &<MyFunc>));


You will experience problems if the lifetime of the <SIGNAL> object
exceeds the lifetime of the <MyClass> object: The connection won't
be destroyed automatically and unless you destroy the connection
manually your program segfaults on <SIGNAL>.emit()!

By the way: According to my rusty c++ knowledge you should only
use virtual base classes if you really need them for efficiency reasons.



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