Pazuzu156
Pazuzu156

Reputation: 679

C++ g_signal_connect Passing data

I'm attempting to connect an object to destroy a widget, but nothing is happening, and I'm getting an error

Here's the call:

g_signal_connect(bKill, "clicked", G_CALLBACK(AppWindow::kill), (gpointer *)bBuzz);

And the method:

void AppWindow::kill(GtkWidget* widget, gpointer data)
{
    gtk_widget_destroy(GTK_WIDGET(data));
}

However, nothing is happening. Almost as if the method isn't even being called. using g_print to check if it's called also doesn't work.

Here's the error I get:

(kpf:15885): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(kpf:15885): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

Am I missing something? Or have I really botched this code up? I'm still a bit new to GTK, so I'm sure something is wrong..

Upvotes: 1

Views: 1961

Answers (1)

andlabs
andlabs

Reputation: 11598

You can't pass a class method to g_signal_connect(), as those have an implicit first parameter that becomes this. You'll have to use a regular function and find a way to pass both the bBuzz variable and the this pointer in the data parameter.

(Alternatively you can use gtkmm, which has been fully optimized for C++.)

Upvotes: 4

Related Questions