Re: gtk_signal_connect() and passing parameters
- From: Darin Adler <darin bentspoon com>
- To: Mazur Przemyslaw <shem_mazur yahoo com au>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk_signal_connect() and passing parameters
- Date: Tue, 15 May 2001 17:30:16 -0700
On Tuesday, May 15, 2001, at 05:22 PM, Mazur Przemyslaw wrote:
I'm having trouble passing any kind of parameters to
my call back functions. For example:
int i = 1456;
...
gtk_signal_connect(GTK_OBJECT(button1),
"button_press_event",
GTK_SIGNAL_FUNC(button1_callback), (gpointer) &i);
...
void button1_callback(GtkWidget *widget, gpointer
data)
{
g_print("i: %d\n", *((int *)data));
}
Quite simply, I expect to see g_print() print 1456 as
the value of i. It does not. Instead, it prints 4.
Even more strange, if I double click on the button
(which is a checkbox button), it prints 5 instead.
There are two problems with the code you posted here:
1) The button_press_event signal has an additional parameter that you
are not including in the declaration of your callback function.
2) It looks like you are passing in the pointer to a local variable
(i).
I think that problem #1 is what's tripping you up. Change your callback to:
void button1_callback(GtkWidget *widget,
GdkEventButton *button,
gpointer data)
{
g_print("i: %d\n", *((int *)data));
}
If i is a local variable, you have a separate problem.
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]