I am having following code/function which adds list of components to the GtkScrolledView.
It first adds GtkButton (with GtkLabel+GtkImage in it) to GtkVBox and GtkVBox to GtkScrolledWindow:
void displayTestNameList()
{
// Get Scrolled Window from Builder.
GtkWidget *scrolled_window = GTK_WIDGET( gtk_builder_get_object( myBuilder, "scrolled_window_name_list"));
GtkWidget *vBox, *image, *button, *hbox, *label;
// Delete Old List --> Error On This Line
if( member_name_list_vbox )
g_object_unref( G_OBJECT(member_name_list_vbox));
//Create new GtkVBox to display name list
member_name_list_vbox = gtk_vbox_new(FALSE, 0);
for(int loopIndex = 0; loopIndex < member_list.size(); loopIndex++)
{
button = gtk_button_new();
gtk_button_set_relief( GTK_BUTTON( button ), GTK_RELIEF_NONE );
gtk_button_set_focus_on_click( GTK_BUTTON( button ), FALSE );
gtk_button_set_alignment( GTK_BUTTON( button ), 0, 1 );
// Attache call back signal.
g_signal_connect(button, "event", G_CALLBACK(cb_user_options), NULL);
// Set Presence Status icon
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(button), hbox);
image = gtk_image_new_from_file("icon.png");
// Create Label
label = gtk_label_new(NULL);
gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_LEFT );
gtk_misc_set_alignment( GTK_MISC(label), 0, 1 );
gtk_misc_set_padding( GTK_MISC(label), 10, 2 );
markup = g_markup_printf_escaped ("<span foreground='#151B54'><b>%s</b></span>", (const char*)(member_list[loopIndex].name) );
gtk_label_set_markup( GTK_LABEL(label), markup );
g_free (markup);
// Create Custom Composite GtkButton Widget (GtkImage+GtkLabel)
gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
// Add this to Class Member GtkVBox
gtk_box_pack_start( GTK_BOX(member_name_list_vbox), button, FALSE, FALSE, 0);
}
// Add GtkVBox To GtkScrollWindow
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(scrolled_window),
member_name_list_vbox );
//Show Scrolled Window
gtk_widget_show_all( scrolled_window );
}
In this function member_name_list_vbox
is a class member which holds pointer to GtkVBox which is getting added in GtkSrolledWindow.
But problem is that the function gets called on some external event(s) n number of times.
And I need to refresh whole list by removing all the widgets and adding them again.
How can I do this?
I tried to unref GtkVBox g_object_unref( G_OBJECT(member_name_list_vbox));
which is my member. But it is giving run-time error when function gets called 2nd time:
(App:7614): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `(null)'
(App:7614): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
(App:7614): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `(null)'
(App:7614): GLib-GObject-CRITICAL **: g_signal_handlers_destroy: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
And if I don't unref GtkVBox before creating new GtkVBox, I get Error While Adding GtkVBox to GtkScrolledWindow.
Run time Error when function gets called 2nd time:
(App:8618): Gtk-CRITICAL **: gtk_scrolled_window_add_with_viewport: assertion `GTK_BIN (bin->child)->child == NULL' failed
Can some one provide some help with this issue?