Re: Passing values to functions
- From: Dino Cherian K <inimss yahoo com>
- To: zze-coframi balr001 <coframi balr001 rd francetelecom com>
- Cc: gtk-list gnome org
- Subject: Re: Passing values to functions
- Date: Sun, 20 Jan 2002 12:51:58 +0530
Hi
I didn't actually get the actual use of such an argument (the gpointer
data). Would you please explain a bit in detail, with a typical
use/application.
Thanks
Dino
zze-coframi balr001 wrote:
>
> Hello,
>
> you have to cast your data before sending them.
> For example, if you want to pass a char *, in your callbacks, you can use
> data as a char *.
>
> char * toto = "My data";
> gtk_signal_connect (GTK_OBJECT (button), "pressed",
> GTK_SIGNAL_FUNC(callback), (char *) toto);
>
> void callback (GtkButton * button, gpointer data){
> printf ("%d\n", (char *) data);
> }
>
> You can pass all kind of pointer you want (GtkWidget *, char *, int * .....)
> , you just have to cast them before using them.
>
> Isabelle
>
> -----Message d'origine-----
> De : Dino Cherian K [mailto:inimss yahoo com]
> Envoye : dimanche 20 janvier 2002 07:32
> A : Sven Neumann
> Cc : Shiraz Baig; gtk-list gnome org
> Objet : Re: Passing values to functions
>
> Hi
>
> Seeing this discussion I have a doubt.
>
> What does this gpointer data in the function arguments mean.
> How I can use it and in what all contexts.
> > void callback (GtkButton *button,
> > gpointer data);
>
> Thanks
> Dino
>
> Sven Neumann wrote:
> >
> > Hi,
> >
> > Shiraz Baig <shiraz_baig yahoo com> writes:
> >
> > > I am a newbie. Can anyone tell me, in the following
> > > elementary program, why doesn't the function "hello"
> > > that it has not been passed any data. Because in
> > > gtk-signal-connect, we are passing NULL data.
> > > Wherefrom is this data coming. In another case, I have
> > > seen drawing_area being passed like this. How does it
> > > get to the function "hello".
> >
> > what was the question again? The code you posted looks
> > OK and I can't see what your question is. data as passed
> > to the function hello should indeed be NULL.
> >
> > If you have seen a drawing_area pointer in a signal
> > callback where you expected your user_data you most
> > probably connected a callback with a wrong signature.
> > Not all signals are declared as the clicked signal
> > of a GtkButton:
> >
> > void (* clicked) (GtkButton *button);
> >
> > which expects a callback of the form
> >
> > void callback (GtkButton *button,
> > gpointer data);
> >
> > The signal "expose_event" of a GtkWidget for
> > example is defined as
> >
> > gint (* expose_event) (GtkWidget *widget,
> > GdkEventExpose *event);
> >
> > so you need to use a callback of the form
> >
> > gint callback (GtkWidget *widget,
> > GdkEventExpose *event,
> > gpointer data);
> >
> > Or you'd get the event pointer instead of the expected
> > user_data.
> >
> > Salut, Sven
> > _______________________________________________
> > gtk-list mailing list
> > gtk-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtk-list
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]