Re: Can't correctly set data to an object (button) is now OK



Hi,

OK it works, I put below my new function is case someone will fall in the
same problem

void
on_view_profile_toggled        (GtkButton       *button,
                                        gpointer
EditEndpointWindow)
{

      GtkWidget   *button_label = NULL;
      GtkWidget   *profile_entry = NULL;
      gchar             *attached_data;
      gchar       *profile_name;


      profile_entry = lookup_widget(EditEndpointWindow,
"profile_combo_entry");
      profile_name = g_strdup(gtk_entry_get_text((GtkEntry *)
profile_entry));

      button_label = lookup_widget(EditEndpointWindow,  "button_label");


      attached_data = gtk_object_get_data(GTK_OBJECT (button),
"profile_name");

      if(gtk_toggle_button_get_active((GtkToggleButton *) button) == TRUE)
      {

            gtk_label_set_text((GtkLabel *) button_label,"View Current");

            gtk_entry_set_text((GtkEntry *) profile_entry, "DEFAULT");

            gtk_object_set_data_full(GTK_OBJECT (button),"profile_name",
profile_name, (GtkDestroyNotify) g_free);
      }

      else
      {

            gtk_label_set_text((GtkLabel *) button_label,"View Default");

            gtk_entry_set_text((GtkEntry *) profile_entry, attached_data);

            profile_name = g_strdup("DEFAULT");
            gtk_object_set_data_full(GTK_OBJECT (button),"profile_name",
profile_name, (GtkDestroyNotify) g_free);
      }
}



|---------+--------------------------->
|         |           Sven Neumann    |
|         |           <sven gimp org> |
|         |           Sent by:        |
|         |           gtk-list-admin g|
|         |           nome.org        |
|         |                           |
|         |                           |
|         |           31/07/2002 14:57|
|         |                           |
|---------+--------------------------->
  >-------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                               |
  |        To:      philippe vivarelli mindspeed com                                                                              |
  |        cc:      gtk-list gnome org                                                                                            |
  |        Subject: Re: Can't correctly set data to an object (button)                                                            |
  >-------------------------------------------------------------------------------------------------------------------------------|




Hi,

philippe vivarelli mindspeed com writes:

> Well I  have toggle button to wich I attached a default string
("DEFAULT")
> using the gtk_object_set_user_data function.
>
> In the callback toggle function I reassign this string regarding the
state
> of the button.
>
> I pick up the new string from a gtk_entry.

you use gtk_entry_get_text() which returns a pointer to the string
owned by the GtkEntry. This pointer becomes invalid as soon as the
text in the entry changes. You'll want to g_strdup() it and use
g_object_set_data_full() with g_free() as destroy notifier.


Salut, Sven
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list








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