GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 27, 2016 8:07 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Assertion failure when recreating a GtkIconView widget
PostPosted: Mon Nov 26, 2007 2:43 am 
Familiar Face

Joined: Sun Nov 04, 2007 10:46 am
Posts: 12
hello every body,
I created a GUI which includes a GtkIconView widget using glade2. Then I tried to fill the IconView widget with necessary icons. So I commented the gtk_icon_view_new() in the interface.c and re-crated a GtkIconView Widget with a model using gtk_icon_view_new_with_model(), I refer the generated GtkIconView Widget using lookup_widget() function generate by glade. So the code which generate this model and displaying will be done when user clicked a button, But when I clicked the button again for the second time I got the following error(Of course this works fine for the first time, and when click the button again and again for the 2nd, 3rd time this gives the error).

17116): Gtk-CRITICAL **: gtk_scrolled_window_add: assertion `bin->child == NULL' failed

The generated code for interface.c (including the commented gtk_icon_view_new()) code as follows
create_main_window (void)
  GtkWidget *main_window;
  GtkWidget *vbox1;
  GtkWidget *menubar1;
  GtkWidget *menuitem1;
  GtkWidget *menu1;
  GtkWidget *new1;
  GtkWidget *open1;
  GtkWidget *save1;
  GtkWidget *save_as1;
  GtkWidget *separatormenuitem1;
  GtkWidget *quit1;
  GtkWidget *menuitem2;
  GtkWidget *menu2;
  GtkWidget *cut1;
  GtkWidget *copy1;
  GtkWidget *paste1;
  GtkWidget *delete1;
  GtkWidget *menuitem3;
  GtkWidget *menu3;
  GtkWidget *menuitem4;
  GtkWidget *menu4;
  GtkWidget *about1;
  GtkWidget *hpaned1;
  GtkWidget *vbox2;
  GtkWidget *info_label;
  GtkWidget *name_lable;
  GtkWidget *name_entry;
  GtkWidget *id_label;
  GtkWidget *id_entry;
  GtkWidget *search_button;
  GtkWidget *exit_button;
  GtkWidget *scrolledwindow1;
  GtkWidget *iconview1;
  GtkAccelGroup *accel_group;

  accel_group = gtk_accel_group_new ();

  main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (main_window, 700, 500);
  gtk_window_set_title (GTK_WINDOW (main_window), _("eXtractor"));

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (main_window), vbox1);

  menubar1 = gtk_menu_bar_new ();
  gtk_widget_show (menubar1);
  gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0);

  menuitem1 = gtk_menu_item_new_with_mnemonic (_("_File"));
  gtk_widget_show (menuitem1);
  gtk_container_add (GTK_CONTAINER (menubar1), menuitem1);

  menu1 = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menu1);

  new1 = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
  gtk_widget_show (new1);
  gtk_container_add (GTK_CONTAINER (menu1), new1);

  open1 = gtk_image_menu_item_new_from_stock ("gtk-open", accel_group);
  gtk_widget_show (open1);
  gtk_container_add (GTK_CONTAINER (menu1), open1);

  save1 = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
  gtk_widget_show (save1);
  gtk_container_add (GTK_CONTAINER (menu1), save1);

  save_as1 = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
  gtk_widget_show (save_as1);
  gtk_container_add (GTK_CONTAINER (menu1), save_as1);

  separatormenuitem1 = gtk_separator_menu_item_new ();
  gtk_widget_show (separatormenuitem1);
  gtk_container_add (GTK_CONTAINER (menu1), separatormenuitem1);
  gtk_widget_set_sensitive (separatormenuitem1, FALSE);

  quit1 = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
  gtk_widget_show (quit1);
  gtk_container_add (GTK_CONTAINER (menu1), quit1);

  menuitem2 = gtk_menu_item_new_with_mnemonic (_("_Edit"));
  gtk_widget_show (menuitem2);
  gtk_container_add (GTK_CONTAINER (menubar1), menuitem2);

  menu2 = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem2), menu2);

  cut1 = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
  gtk_widget_show (cut1);
  gtk_container_add (GTK_CONTAINER (menu2), cut1);

  copy1 = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
  gtk_widget_show (copy1);
  gtk_container_add (GTK_CONTAINER (menu2), copy1);

  paste1 = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
  gtk_widget_show (paste1);
  gtk_container_add (GTK_CONTAINER (menu2), paste1);

  delete1 = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
  gtk_widget_show (delete1);
  gtk_container_add (GTK_CONTAINER (menu2), delete1);

  menuitem3 = gtk_menu_item_new_with_mnemonic (_("_View"));
  gtk_widget_show (menuitem3);
  gtk_container_add (GTK_CONTAINER (menubar1), menuitem3);

  menu3 = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem3), menu3);

  menuitem4 = gtk_menu_item_new_with_mnemonic (_("_Help"));
  gtk_widget_show (menuitem4);
  gtk_container_add (GTK_CONTAINER (menubar1), menuitem4);

  menu4 = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem4), menu4);

  about1 = gtk_menu_item_new_with_mnemonic (_("_About"));
  gtk_widget_show (about1);
  gtk_container_add (GTK_CONTAINER (menu4), about1);

  hpaned1 = gtk_hpaned_new ();
  gtk_widget_show (hpaned1);
  gtk_box_pack_start (GTK_BOX (vbox1), hpaned1, TRUE, TRUE, 0);
  gtk_paned_set_position (GTK_PANED (hpaned1), 0);

  vbox2 = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox2);
  gtk_paned_pack1 (GTK_PANED (hpaned1), vbox2, FALSE, FALSE);

  info_label = gtk_label_new (_("Enter name and id to \n retrive index cards\n"));
  gtk_widget_show (info_label);
  gtk_box_pack_start (GTK_BOX (vbox2), info_label, FALSE, FALSE, 7);

  name_lable = gtk_label_new (_("Name"));
  gtk_widget_show (name_lable);
  gtk_box_pack_start (GTK_BOX (vbox2), name_lable, FALSE, FALSE, 2);

  name_entry = gtk_entry_new ();
  gtk_widget_show (name_entry);
  gtk_box_pack_start (GTK_BOX (vbox2), name_entry, FALSE, FALSE, 1);
  gtk_entry_set_invisible_char (GTK_ENTRY (name_entry), 8226);

  id_label = gtk_label_new (_("ID"));
  gtk_widget_show (id_label);
  gtk_box_pack_start (GTK_BOX (vbox2), id_label, FALSE, FALSE, 4);

  id_entry = gtk_entry_new ();
  gtk_widget_show (id_entry);
  gtk_box_pack_start (GTK_BOX (vbox2), id_entry, FALSE, FALSE, 0);
  gtk_entry_set_invisible_char (GTK_ENTRY (id_entry), 8226);

  search_button = gtk_button_new_with_mnemonic (_("Search"));
  gtk_widget_show (search_button);
  gtk_box_pack_start (GTK_BOX (vbox2), search_button, FALSE, FALSE, 4);

  exit_button = gtk_button_new_with_mnemonic (_("Exit"));
  gtk_widget_show (exit_button);
  gtk_box_pack_start (GTK_BOX (vbox2), exit_button, FALSE, FALSE, 2);

  scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (scrolledwindow1);
  gtk_paned_pack2 (GTK_PANED (hpaned1), scrolledwindow1, TRUE, TRUE);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN);

  //iconview1 = gtk_icon_view_new();
  //gtk_widget_show (iconview1);
  //gtk_container_add (GTK_CONTAINER (scrolledwindow1), iconview1);

  g_signal_connect ((gpointer) main_window, "delete_event",
                    G_CALLBACK (on_window1_delete_event),
  g_signal_connect ((gpointer) new1, "activate",
                    G_CALLBACK (on_new1_activate),
  g_signal_connect ((gpointer) open1, "activate",
                    G_CALLBACK (on_open1_activate),
  g_signal_connect ((gpointer) save1, "activate",
                    G_CALLBACK (on_save1_activate),
  g_signal_connect ((gpointer) save_as1, "activate",
                    G_CALLBACK (on_save_as1_activate),
  g_signal_connect ((gpointer) quit1, "activate",
                    G_CALLBACK (on_quit1_activate),
  g_signal_connect ((gpointer) cut1, "activate",
                    G_CALLBACK (on_cut1_activate),
  g_signal_connect ((gpointer) copy1, "activate",
                    G_CALLBACK (on_copy1_activate),
  g_signal_connect ((gpointer) paste1, "activate",
                    G_CALLBACK (on_paste1_activate),
  g_signal_connect ((gpointer) delete1, "activate",
                    G_CALLBACK (on_delete1_activate),
  g_signal_connect ((gpointer) about1, "activate",
                    G_CALLBACK (on_about1_activate),
  g_signal_connect ((gpointer) name_entry, "activate",
                    G_CALLBACK (on_name_entry_activate),
  g_signal_connect ((gpointer) id_entry, "activate",
                    G_CALLBACK (on_id_entry_activate),
  g_signal_connect ((gpointer) search_button, "button_press_event",
                    G_CALLBACK (on_search_button_button_press_event),
  g_signal_connect ((gpointer) exit_button, "button_press_event",
                    G_CALLBACK (on_exit_button_button_press_event),

  /* Store pointers to all widgets, for use by lookup_widget(). */
  GLADE_HOOKUP_OBJECT_NO_REF (main_window, main_window, "main_window");
  GLADE_HOOKUP_OBJECT (main_window, vbox1, "vbox1");
  GLADE_HOOKUP_OBJECT (main_window, menubar1, "menubar1");
  GLADE_HOOKUP_OBJECT (main_window, menuitem1, "menuitem1");
  GLADE_HOOKUP_OBJECT (main_window, menu1, "menu1");
  GLADE_HOOKUP_OBJECT (main_window, new1, "new1");
  GLADE_HOOKUP_OBJECT (main_window, open1, "open1");
  GLADE_HOOKUP_OBJECT (main_window, save1, "save1");
  GLADE_HOOKUP_OBJECT (main_window, save_as1, "save_as1");
  GLADE_HOOKUP_OBJECT (main_window, separatormenuitem1, "separatormenuitem1");
  GLADE_HOOKUP_OBJECT (main_window, quit1, "quit1");
  GLADE_HOOKUP_OBJECT (main_window, menuitem2, "menuitem2");
  GLADE_HOOKUP_OBJECT (main_window, menu2, "menu2");
  GLADE_HOOKUP_OBJECT (main_window, cut1, "cut1");
  GLADE_HOOKUP_OBJECT (main_window, copy1, "copy1");
  GLADE_HOOKUP_OBJECT (main_window, paste1, "paste1");
  GLADE_HOOKUP_OBJECT (main_window, delete1, "delete1");
  GLADE_HOOKUP_OBJECT (main_window, menuitem3, "menuitem3");
  GLADE_HOOKUP_OBJECT (main_window, menu3, "menu3");
  GLADE_HOOKUP_OBJECT (main_window, menuitem4, "menuitem4");
  GLADE_HOOKUP_OBJECT (main_window, menu4, "menu4");
  GLADE_HOOKUP_OBJECT (main_window, about1, "about1");
  GLADE_HOOKUP_OBJECT (main_window, hpaned1, "hpaned1");
  GLADE_HOOKUP_OBJECT (main_window, vbox2, "vbox2");
  GLADE_HOOKUP_OBJECT (main_window, info_label, "info_label");
  GLADE_HOOKUP_OBJECT (main_window, name_lable, "name_lable");
  GLADE_HOOKUP_OBJECT (main_window, name_entry, "name_entry");
  GLADE_HOOKUP_OBJECT (main_window, id_label, "id_label");
  GLADE_HOOKUP_OBJECT (main_window, id_entry, "id_entry");
  GLADE_HOOKUP_OBJECT (main_window, search_button, "search_button");
  GLADE_HOOKUP_OBJECT (main_window, exit_button, "exit_button");
  GLADE_HOOKUP_OBJECT (main_window, scrolledwindow1, "scrolledwindow1");
  GLADE_HOOKUP_OBJECT (main_window, iconview1, "iconview1");

  gtk_window_add_accel_group (GTK_WINDOW (main_window), accel_group);

  return main_window;

The code which again create the GtkIconView Widget and display the icons as follows.It is the button which gives the above error when clicked again. This is done in callback.c source file.


on_search_button_button_press_event    (GtkWidget       *widget,
                                        GdkEventButton  *event,
                                        gpointer         user_data)
    GtkTreeModel *model = GTK_TREE_MODEL(create_liststore());
    GtkWidget *iconview = NULL;
    GtkWidget *scrollwindow = NULL;
    if(displayed_treeview == FALSE){
        iconview = lookup_widget(GTK_WIDGET(widget), "iconview1");   
        if(iconview == NULL)
            g_print("icon view widget not found\n");
        scrollwindow = lookup_widget(GTK_WIDGET(widget), "scrolledwindow1");   
        if(scrollwindow == NULL)
            g_print("scroll window widget not found\n");
        iconview = gtk_icon_view_new_with_model(model);     
        gtk_icon_view_set_selection_mode(iconview, GTK_SELECTION_MULTIPLE);
        gtk_icon_view_set_columns(iconview, 0);
        gtk_icon_view_set_item_width(iconview, 50);   
        gtk_container_add(GTK_CONTAINER(scrollwindow), iconview);
        g_signal_connect(iconview, "item-activated", (GCallback)select_callback, NULL);
        //displayed_treeview = TRUE;
        g_print("searched result already displayed\n");
    return FALSE;

Please help me to figure out the problem. Thanks in advance.


 Post subject:
PostPosted: Wed Nov 28, 2007 5:21 am 
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
First, you're using the code generation from glade? That's deprecated and should probably be avoided.

Secondly, the error is "gtk_scrolled_window_add: assertion `bin->child == NULL' failed"

What that's telling you, is that the function gtk_scrolled_window_add failed because the scolled window's child should be NULL (shouldn't have a child) before adding a child. A GtkScrolledWindow, derived from GtkBin, only holds one child.

You button callback has this function:

gtk_container_add(GTK_CONTAINER(scrollwindow), iconview);

Which means you're trying to add iconview to the scrolled window every time the button is clicked. You only need to add the iconview to the scrolled window once--when you create it.

Micah Carrick - Forum Administrator

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group