tags:

views:

84

answers:

1

How can I send data through a GTK callback? I've Googled, and with the information I found created this:

#include <gtk/gtk.h>
#include <stdio.h>
void button_clicked( GtkWidget *widget, GdkEvent *event, gchar *data);

int main( int argc, char *argv[]){
    GtkWidget *window;

    GtkWidget *button;

    gtk_init (&argc, &argv);


    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    button = gtk_button_new_with_label("Go!");


    gtk_container_add(GTK_CONTAINER(window), button);

    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_clicked),"test" );

    gtk_widget_show(window);
    gtk_widget_show(button);

    gtk_main();
    return 0;
}

void button_clicked( GtkWidget *widget, GdkEvent *event, gchar *data){
    printf("%s \n", (gchar *) data);
    return;
}

But it just Segfaults when I press the button. What is the right way to do this?

+2  A: 

It segfaults because "clicked" doesn't have a GdkEvent parameter. If you remove the second argument in button_clicked() it should work.

Install Devhelp application from where you can easily browse GTK+ and GNOME documentation, including signal definitions.

doublep
That works, thanks!I had Devhelp installed (Quickly dependency) but never looked at it. That should be a huge help, double thanks! :)
snostorm