[英]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
的值,但不是打印 23,而是继续打印一些地址 11652528 等...
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.我在网上搜索了很多,根据旧的 GTK 教程(实际的
G_CALLBACK
宏是GTK_SIGNAL_FUNC
)这应该可以工作。
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 advance!!!先感谢您!!!
The "delete-event"
signal callback takes three arguments. "delete-event"
信号回调需要三个arguments。
The function signature for f_window
should be GtkWidget* widget, GdkEvent *event, gpointer data
. f_window 的
f_window
签名应该是GtkWidget* widget, GdkEvent *event, gpointer data
。
You are actually printing the value of event
in your code.您实际上是在代码中打印
event
的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.