GTK g_signal_connect()中gpointer的问题

王成展 发布于 2012/02/14 15:54
阅读 2K+
收藏 1
gint count = 1;
==========
void on_button_clicked(GtkWidget *button, gpointer userdata)
{
    g_print("hello,this is hello test ");
    g_print("%d\n", (gint)(userdata));
    count = count + 1;
}
==========
g_signal_connect(G_OBJECT(button), "clicked",
            G_CALLBACK(on_button_clicked), (gpointer)count);
==========
打出来都是1
加载中
0
周翼翼
周翼翼
g_signal_connect(G_OBJECT(button), "clicked",
            G_CALLBACK(on_button_clicked), (gpointer) &count);
 g_print("%d\n", *((gint*)userdata));
gpinter 是void*的typedef.所以你要传地址进去,然后在函数是对指针进行*
王成展
果然...我其实后来用gpoint gp; gp = &count;来控制,也可以了...其实就差一个&,谢谢
返回顶部
顶部