简体   繁体   中英

Sending data in a GTK Callback

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM