Re: array of widgets...



The problem is simple: the entry array is a local variable (local to
function) and it gets destroyed when you exit the function.

Better try this way:

  GtkWidget **entry;
  entry = (GtkEntry**)malloc(sizeof(GtkEntry*) * 3);

  ...

  /* pass it to the signal handler.. */
  gtk_signal_connect(GTK_OBJECT(button), "clicked",
                     GTK_SIGNAL_FUNC(your_func), entry);
  ...
} /* function ends here, the entry pointer is lost, but memory remains
   * alloc-ed, so you don't receive an invalid pointer in your signal
   * handler */

Remember to free() this memory at one point when you don't need it
anymore.

Cheers,
-- mishoo

On Fri, 17 Aug 2001 16:47:50 -0300
"Luiz Octavio de Almeida Soares" <loas procc fiocruz br> wrote:

what's the best way of passing an array of widgets to a callback? I've
tried
many ways but cant seem to get this to work.

imagine sth like:
GtkWidget *entry[3];
GtkWidget *button;

button = gtk_button_new...
entry[0] = gtk_entry_new...
entry[1] ...

and i have a function named my_callback and i want it to receive the
array
as a parameter when the user clicks the button. I tried many things with
gtk_signal_connect but none of them worked. Can anyone plz come up with
a
simple solution for this?

-- 

  "For millions of years, mankind lived just like the animals.
   Then something happened, which unleashed the power of our
   imagination: we learned to talk."         -- Pink Floyd




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