B
Bo Møller
The signature in the documentation is described as ( Taken from http://
library.gnome.org/devel/gobject/unstable/gobject-Closures.html#GCallback )
---------------------------------------------
void (*GCallback) (void);
---------------------------------------------
The type used for callback functions in structure definitions and function
signatures. This doesn't mean that all callback functions must take no
parameters and return void. The required signature of a callback function
is determined by the context in which is used (e.g. the signal to which it
is connected). Use G_CALLBACK() to cast the callback function to a
GCallback.
---------------------------------------------
The examples given in the tutorials have signatures like: gboolean
delete_event( GtkWidget *widget,GdkEvent *event, gpointer data) which
does not fit the signature in the docs, but a old-style cast (in the
tutorial disguised as a macro) shuts up the compiler in the tutorials!
So far I have come up with:
gulong m_destroyHandlerID;
boost::function<bool (GtkWidget*, GdkEvent*, gpointer)>
m_destroyFunctionPtr;
// SignalMember is a nonstatic member function of the Window class.
m_destroyFunctionPtr = boost::bind(&Window::SignalMember, this, _1,_2,_3);
m_destroyHandlerID = g_signal_connect_data (m_widget, "delete-event",
m_destroyFunctionPtr, NULL,NULL,0);
When compiling with gcc 4.4.1 gives an error:
error: cannot convert 'boost::function<bool(GtkWidget*, GdkEvent*,
void*)>' to 'void (*)()' for argument '3' to 'gulong
g_signal_connect_data(void*, const gchar*, void (*)(), void*, void
(*)(void*, GClosure*), GConnectFlags)'
The boost::function can't be casted to the needed type.
An obvious hack would be to replace the boost::function with
boost::function<void(void)> but I can't see how it would work when Gtk IS
passing arguments and expects a return type of bool for this particular
event.
Does anyone know how to get GTK to call a non-static member function?
Bo Møller
library.gnome.org/devel/gobject/unstable/gobject-Closures.html#GCallback )
---------------------------------------------
void (*GCallback) (void);
---------------------------------------------
The type used for callback functions in structure definitions and function
signatures. This doesn't mean that all callback functions must take no
parameters and return void. The required signature of a callback function
is determined by the context in which is used (e.g. the signal to which it
is connected). Use G_CALLBACK() to cast the callback function to a
GCallback.
---------------------------------------------
The examples given in the tutorials have signatures like: gboolean
delete_event( GtkWidget *widget,GdkEvent *event, gpointer data) which
does not fit the signature in the docs, but a old-style cast (in the
tutorial disguised as a macro) shuts up the compiler in the tutorials!
So far I have come up with:
gulong m_destroyHandlerID;
boost::function<bool (GtkWidget*, GdkEvent*, gpointer)>
m_destroyFunctionPtr;
// SignalMember is a nonstatic member function of the Window class.
m_destroyFunctionPtr = boost::bind(&Window::SignalMember, this, _1,_2,_3);
m_destroyHandlerID = g_signal_connect_data (m_widget, "delete-event",
m_destroyFunctionPtr, NULL,NULL,0);
When compiling with gcc 4.4.1 gives an error:
error: cannot convert 'boost::function<bool(GtkWidget*, GdkEvent*,
void*)>' to 'void (*)()' for argument '3' to 'gulong
g_signal_connect_data(void*, const gchar*, void (*)(), void*, void
(*)(void*, GClosure*), GConnectFlags)'
The boost::function can't be casted to the needed type.
An obvious hack would be to replace the boost::function with
boost::function<void(void)> but I can't see how it would work when Gtk IS
passing arguments and expects a return type of bool for this particular
event.
Does anyone know how to get GTK to call a non-static member function?
Bo Møller