开发者

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_CALL开发者_如何学编程BACK(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜