Re: can I pass user data to a button callback?
- From: "Leandro A. F. Pereira" <leandro linuxmag com br>
- To: gtk-app-devel-list gnome org
- Subject: Re: can I pass user data to a button callback?
- Date: Mon, 14 Feb 2005 22:33:48 -0200
On Tue, 2005-02-15 at 00:34 +0100, Felix Kater wrote:
can I pass (a pointer to) user data to a button's callback? The compiler
wants me to create button callbacks like void (*)(void) -- but what I
need is void (*)(void*), at least for the "pressed" and "released"
signals
You may try the following untested code:
typedef struct _MyData MyData;
struct _MyData {
char *text;
};
void my_callback(GtkWidget *wid, gpointer data)
{
MyData *mydata = (MyData *)data;
g_print("data: %s\n", mydata->text);
}
void some_function()
{
MyData *mydata;
GtkWidget *button;
button = gtk_button_new_with_label("Foo");
gtk_widget_show(button);
mydata = g_new0(MyData);
mydata->text = g_strdup("Bar");
g_signal_connect(G_OBJECT(button), "clicked",
(GCallback) my_callback, mydata);
}
Leandro
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]