Passing additional arguments to gtk function

后端 未结 3 1261
夕颜
夕颜 2020-12-18 11:46

I\'m trying to learn how to make GUIs using gtk+ 3.0. I want to pass a simple argument, an integer, to a callback function, so that when I press the button the value of the

3条回答
  •  -上瘾入骨i
    2020-12-18 12:40

    There are a bunch of useful macros which store an integer (32bit, no longer!) into a pointer.

    int a = 42;
    gpointer ptr = GINT_TO_POINTER (a)
    //GUINT_TO_POINTER (a), GBOOLEAN_TO_POINTER (a), GSIZE_TO_POINTER (a)
    

    reverse:

    int a2 = GPOINTER_TO_INT (ptr);
    //GPOINTER_TO_UINT (ptr), GPOINTER_TO_...
    

提交回复
热议问题