Re: Connecting to a signal given as a string



On Sun, 26 Oct 2008 11:28:58 +0100
"Søren Hauberg" <hauberg gmail com> wrote:

> I've tried the following:
> 
>       g_signal_connect (G_OBJECT (html_widget), "load_finished",
>                         G_CALLBACK (on_page_loaded), this);
> 
> in the constructor of the class that does the rendering. Then I have
> the following function
> 
>       static void on_page_loaded (WebView *web_view)
>       {
>         web_view->on_load_finished ();
>       }
> 
> that calls the member function of my choice. But this gives my a
> segfault. Is there anything obviously wrong with this?

Either your object whose 'this' pointer you passed in no longer exists
when the callback is executed, or your on_load_finished() method is
defective in some way. What does the debugger show?

Actually there is another issue, which will not bite if you are using
gcc, namely that your on_page_loaded() function will have C++ linkage.
It is better to declare it extern "C". which means you then need to put
it in anonymous namespace in order for it not to be exported. Something
like:

namespace {
extern "C" {
void on_page_loaded (WebView *web_view)
{
  web_view->on_load_finished ();
}
} // extern "C"
} // anonymous namespace




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