Re: problem with gtk_radio_tool_button_set_group function/



Hello.

I think that this mailing list is for asking questions about
development of GTK+ itself. For questions about programming using
GTK+, use gtk-list or gtk-app-devel-list. I'm redirecting this to
gtk-list.

>         radio_tool_btn_1 = gtk_radio_tool_button_new(NULL);
> if(radio_tool_btn_1 == NULL)
> {
>                  return; /// or doing some thing else,
> }
> group1 =
> gtk_radio_tool_button_get_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_1));
> if(group1 == NULL)
> {
>                  return; /// or doing some thing else,
> }
> radio_tool_btn_2 = gtk_radio_tool_button_new(NULL);
> if(radio_tool_btn_2 == NULL)
> {
>                  return; /// or doing some thing else,
> }
> group2 =
> gtk_radio_tool_button_get_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_2));
> if(group2 == NULL)
> {
>                  return; /// or doing some thing else,
> }
> add_group_length_before = g_slist_length(group2);
> gtk_radio_tool_button_set_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_2),
> group1);
> add_group_length_after = g_slist_length(group2);
>         printf("after:%d\nbefore:%d\n", add_group_length_after,
> add_group_length_before);

This code performs just fine, your expectations are wrong. When you
move your second button from it's own group to first group, group2
doesn't exists anymore and the second g_slist_length() call could as
well segfault.

Have a look at this updated code:

#include <gtk/gtk.h>

int
main (int    argc,
      char **argv)
{
  gtk_init (&argc, &argv);

  GtkWidget *radio_tool_btn_1 = gtk_radio_tool_button_new(NULL);
  GSList *group1 =
    gtk_radio_tool_button_get_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_1));

  GtkWidget *radio_tool_btn_2 = gtk_radio_tool_button_new(NULL);
  GSList *group2 =
    gtk_radio_tool_button_get_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_2));

  gint add_group_length_before = g_slist_length(group2);
  gtk_radio_tool_button_set_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_2),
				  group1);

  group2 =
    gtk_radio_tool_button_get_group(GTK_RADIO_TOOL_BUTTON(radio_tool_btn_2));
  gint add_group_length_after = g_slist_length(group2);

  g_printf("after:%d\nbefore:%d\n",
	   add_group_length_after, add_group_length_before);

  return 0;
}

This will probably give you the results you expect.

Tadej

-- 
Tadej Borovšak
tadeboro.blogspot.com
tadeboro gmail com
tadej borovsak gmail com


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