[webkit-gtk] Access web view in g_signal_callback

Brendan Long self at brendanlong.com
Tue Aug 19 08:22:04 PDT 2014


On 08/18/2014 11:35 PM, Dub wrote:
> So I have a
>
> struct data {
>     WebKitWebView *web_view;
> };
>
> And I start the webview and add it too my window
>
> data.web_view = (WebKitWebView *) webkit_web_view_new();
> GtkWidget *web_window = gtk_scrolled_window_new(NULL, NULL);
> gtk_container_add(GTK_CONTAINER(web_window), GTK_WIDGET(notes.web_view));
>
> And then I have a signal
>
> g_signal_connect(blah, "blah", G_CALLBACK(function), &data);
>
> And a function
>
> void function(struct data *blah) {
>     webkit_web_view_load_html(blah->web_view, html, NULL);
> }
>
> And everything but the callback works, when I press the button I get
>
> ** CRITICAL **: void webkit_web_view_load_html(WebKitWebView*, const
> gchar*, const gchar*): assertion 'WEBKIT_IS_WEB_VIEW(webView)' failed
>
> But the passed in value is the webview, I've also tried not using a
> struct and it still isn't working.
>
> Any ideas on what could be wrong? Do I need to wait for it too load or
> do something else? I see the HTML (it's only <h1>Hello</h1> so it
> shouldn't take long) before I press the button.
This is difficult to diagnose, since you left a lot out. A short, self
contained example <http://www.sscce.org/> would help.

Some guesses though:

  * Are you sure void user_function(struct data*) is the correct
    function signature for your callback? A lot of callbacks pass the
    object that fired the signal as the first argument.

    For example, WebKitWebView's "authenticate
    <http://webkitgtk.org/reference/webkit2gtk/unstable/WebKitWebView.html#WebKitWebView-authenticate>"
    expects something like gboolean user_function(WebKitWebView*,
    WebKitAuthenticationRequest*, gpointer) (where gpointer is the data
    you passed to g_signal_connect). Another example is GtkButton's
    "click
    <https://developer.gnome.org/gtk3/unstable/GtkButton.html#GtkButton-clicked>"
    handler, which expects a callback like void
    user_function(GtkButton*, gpointer user_data).

    I suspect this is your problem, but it's impossible to tell because
    you didn't tell us the signal you connected.
  * Another option is that data was freed before the callback was
    called. I suspect you would usually get a different error message in
    this case though, but it's possible.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-gtk/attachments/20140819/102c8495/attachment.html>


More information about the webkit-gtk mailing list