Re: Gtk widgets in gtkmm (Previously no subject)
- From: Chris Vine <chris cvine freeserve co uk>
- To: gtkmm-list gnome org, andrew openldev org
- Cc:
- Subject: Re: Gtk widgets in gtkmm (Previously no subject)
- Date: Sun, 24 Jul 2005 01:23:06 +0100
On Thursday 21 July 2005 16:22, Andrew Krause wrote:
> (Sorry about the no subject topic... in any case...)
>
> I have a c++ class that contains Gtk+ widgets. They work perfectly
> fine except for one thing. When I try to connect a signal to them,
> they throw an error saying that the function that it is connected
> to should be formatted: "void (*) ()" instead of: "void (MyClass) ()".
>
> How can I get around this? Is there a way without requiring all
> of my functions to receive the class data and not be a part of
> the class?
g_signal_connect has its callback (slot) function passed as a C function
pointer (cast with G_CALLBACK()).
The cludge (which will work with most but not all compilers) is to make your
callback a static member function of the class. The correct (standards
complying) approach is to make the callback a function outside the class with
C linkage (ie declare it extern "C") and make it a friend of the class if it
needs access to the class's private or protected members.
You will need to pass the class instance to the callback if the callback needs
to access non-static data of the class. If so pass the "this" pointer as the
last (data) argument to g_signal_connect(), and then cast it back to the
correct type in the callback.
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]