Re: [gtk-list] Re: Need help in GTK-project



On Sun, 12 Dec 1999 12:27:25 +0100, Bart Vandewoestyne wrote:
> Joe Pfeiffer wrote:
>>
>> Bite the bullet, learn to use pointers.  It'll be painful, but in a
>> year you'll wonder why you ever hesitated.
> 
> I already learned about pointers... I know it's painfull ;-)
> But as I mentioned before: I only used pointers in those tiny little
> 'introductory' programs we got to do at school ;-)
> So are you suggesting here that I should change the value of portstatus
> by using pointers and declare portstatus local to main?
> Problem is that I don't quite now how my callback functions should look
> like then.  should I keep them in the form callback(GtkWidget *widget,
> gpointer data) and do the necessary casting in the body ?
> And how about the gtk_signal_connect()'s then, how to pass my arguments
> if I use pointers to change portstatus ?

The gtk_signal_connect() function has an extra argument for data:

  int main(int agrc, char *argv[])
  {
    int portstatus = 0;

    /* setup gtk */
    gtk_signal_connect(GTK_OBJECT (button), "clicked",
                       GTK_SIGNAL_FUNC(cbfunc), &portstatus);

    /* do other important stuff */
  }

  void cbfunc(GtkWidget *widget, gpointer data)
  {
    int *status = (int*)data;
  
    /* do whatever you want to do with the status data */
  }

If you need more data, give it a pointer to a structure.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]