Re: Connecting to a signal given as a string



On Sat, 25 Oct 2008 21:01:09 +0200
"Søren Hauberg" <hauberg gmail com> wrote:

> 
> Hi All,
>   I'm trying to use the webkitgtk library inside my gtkmm app. I can
> get basic functionaliy simply by
> 
>     GtkWidget *html_widget = webkit_web_view_new ();
>     Gtk::Widget *html_widget_mm = Glib::wrap (html_widget);
> 
> after which I can add 'html_widget_mm' to any Gtk::Widget. When I have
> to work with webkit I simply use the C interface, and that works fine
> for everything but for connecting signals. If I want to connect a
> signal in a C app then I can do something like
> 
>     g_signal_connect (G_OBJECT (html_widget), "signal::load_finished",
> G_CALLBACK (some_function), some_data);
> 
> However, this is giving me problems in C++, as I would like to connect
> a non-static member function to this signal. So, I was wondering can I
> somehow connect to this signal through my 'html_widget_mm' variable
> which is of type Gtk::Widget ?

You need to connect the GTK+ signal to a callback function with C
linkage [1], which will have to be a friend function if it needs access
to private or protected data or methods.  You then need to pass the
'this' pointer (or a pointer to some other class instance) as the data
parameter in the call to g_signal_connect, and cast it back to the
relevant type in the callback function and use that to call class
methods or data on that object in the callback function.

Chris

[1] With some compilers, including gcc, you can also use a static
member function, but that is not standard conforming as static member
functions do not have C linkage.



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