Passing variables through callback function in GTK C
I'm trying to print the value of the variable i
on the console from my callback
functon, but instead of printing 23 it keeps printing some address 11652528 etc...
I've been searching quite a lot on the net and according to an old GTK tutorial (where the actual G_CALLBACK
Macro was GTK_SIGNAL_FUNC
) this should work.
Does anyone have an idea where the error is??
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
void f_window(GtkWidget* widget, gpointer data)
{
g_print("%d\n",GPOINTER_TO_INT(data));
}
int main(int argc, char **argv)
{
gint i=23;
GtkWidget * MainWindow = NULL;
gtk_init(&argc, &argv);
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(MainWindow),"delete-event",G_CALLBACK(f_window),GINT_TO_POINTER(i));
gtk_widget_show_all(MainWindow);
gtk_main();
gtk_exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}
thank you in adv开发者_Python百科ance!!!
The "delete-event"
signal callback takes three arguments.
The function signature for f_window
should be GtkWidget* widget, GdkEvent *event, gpointer data
.
You are actually printing the value of event
in your code.
精彩评论