c++ - Reuse a widget using g_object_ref() -



c++ - Reuse a widget using g_object_ref() -

i have gtkgrid , want show within 1 cell widget or according choices of user. wrote code according this, says:

removes widget container . widget must within container . note that container own reference widget , , may be the lastly reference held; removing widget container can destroy widget. if want utilize widget again, need add a reference while it’s not within container, using g_object_ref(). if don’t want utilize widget 1 time again it’s more efficient destroy straight using gtk_widget_destroy() since remove container , help break circular reference count cycles.

here fragment of code:

// definitions gtkwidget *mylist1, *mylist2; // creation mylist1 = gtk_tree_view_new(); mylist2 = gtk_tree_view_new(); gtk_grid_attach(gtk_grid(gridlist), mylist1, 0, 1, 2, 1); // attach mylist1 // switching in runtime if (x) { g_object_ref(mylist1); gtk_container_remove(gtk_container(gridlist), mylist1); gtk_grid_attach(gtk_grid(gridlist), mylist2, 0, 1, 2, 1); } else { g_object_ref(mylist2); gtk_container_remove(gtk_container(gridlist), mylist2); gtk_grid_attach(gtk_grid(gridlist), mylist1, 0, 1, 2, 1); }

when perform switching (i want remove mylist1 , insert mylist2), empty cell in grid. anyway, when repeat switching, object mylist1 reappears in grid want.

i don't gtk warning on terminal during operations. x set true or false correctly according selection of 2 radio buttons.

what's going on? missing passages?

you need gtk_widget_show_all(mylist2) show up. gtk_widget_show_all() shows gtkwindow gtkgrid kid of shows children at time of call.

your code has latent bug: reference counts increment 2 decrement 1 because gtk_grid_attach() (actually gtk_widget_set_parent()) own g_object_ref() (actually g_object_ref_sink()).

c++ c widget gtk

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -