Re: Gtk widgets in gtkmm (Previously no subject)
- From: "Andrew E. Makeev" <andrew solvo ru>
- To: Chris Vine <chris cvine freeserve co uk>
- Cc: andrew openldev org, gtkmm-list gnome org
- Subject: Re: Gtk widgets in gtkmm (Previously no subject)
- Date: Mon, 25 Jul 2005 10:32:19 +0400
Chris Vine wrote:
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.
I only would add one note:
you may wish to use "static" class method as callback for that signal,
then you could save c++ style and avoid friend declarations.
Regards,
-andrew
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]