Re: Parameter passing and gpointers...



On Tue, 2001-11-13 at 12:25, Chris Elston wrote:
Ok, some of you may recall that a few months ago I sent a question talking
about sending multiple params to a signal handler.  One suggestion was
thru using a struct and passing a reference to that struct.  This is
giving me some problems and I'm not sure why.  I only have so much
experience in C so that may be what's wrong.  Here's an example of what
I'm trying to do:

struct MyStruct {
      GtkWidget *entry1;
      GtkWidget *entry2;
}

void create_dialog( void ) {
      struct MyStruct *my_struct;
      .....

I hope that you've done a 
        my_struct = g_malloc (sizeof (struct MyStruct));
        here, right?
      my_struct->entry1 = gtk_entry_new();
      my_struct->entry2 = gtk_entry_new();
      .....
      gtk_signal_connect(
              GTK_OBJECT(some_button), "clicked",
              GTK_SIGNAL_FUNC(my_callback),
              (gpointer) my_struct
      );
      .....
}

void my_callback( GtkWidget *w, gpointer data ) {
      struct MyStruct *local_struct = (struct MyStruct *) data;
      char* some_text = gtk_entry_get_text(
              GTK_ENTRY(local_struct->entry1)
      );
      .....
}


I'm getting all sorts of compile errors trying the above.  I've also tried
to use different pointer syntax but to no avail.  What am I doing wrong?
What do you usually do in this situation?  Are malloc and free necessary
for what I'm doing?

What exactly are the compile error messages?

Alternatively,if there are only two widgets in some common ancestry then
you could bind them to that ancestor by name and retrieve them using the
gtk_object_set_data() and gtk_object_get_data() functions.


-- 

Chris Elston
celston corky sapien net
---------------------------------
Nucleus Communications
Web Script Programmer

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
-- 
regards,

Luciano Chavez

lnx1138 us ibm com          
http://sf.net/projects/evms




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