#include <gtk/gtk.h> //defined combobox combo = gtk_combo_box_new_text(); //added entries gtk_combo_box_append_text(gtk_combo_box(combo), "string"); //how particular entry deleted list of entries in combobox combo? how delete particular entry in combobox? example - combobox dropdown has entries "foo", "boo", "hoo" etc. want select "boo" , remove it? how do ?
//segmentation fault while removal error
mcve -
fixed = gtk_fixed_new(); combo = gtk_combo_box_new_text(); gtk_fixed_put(gtk_fixed(fixed), combo, 50, 50); label = gtk_label_new("rooms"); gtk_fixed_put(gtk_fixed(fixed), label, 50, 30 ); gtk_table_attach_defaults (gtk_table (table), fixed, 2, 3, 0, 2); g_signal_connect(g_object(combo), "changed", g_callback(combo_selected), (gpointer) label); in callback function copy current selection globally declared string. next, in other function try run -
gtk_combo_box_remove_text (gtk_combo_box(combo), gtk_combo_box_get_active (gtk_combo_box(combo))); //statement seg fault occurs the gtk_combo_box_get_active gives me appropriate index entry removed. note - gtkwidget *combo globally defined in program.
the id of active(that selected) entry in combo box can obtained via gtk_combo_box_get_active , can removed of gtk_combo_box_text_remove or gtk_combo_box_remove_text (depending on version of api used. former(gtk_combo_box_text_remove) more date).
gtk_combo_box_get_active returns -1 if there no active item , should therefore checked before passing 1 of remove functions. important if, in case presented above, removing happens in signal handler. according documentation "changed" signal
[...] emitted when active item changed. can due user selecting different item list, or due call gtk_combo_box_set_active_iter(). emitted while typing entry of combo box entry. [...]
as far understand includes when item deselected(which presumably happen if deleted).
your handler should therefore somehow this:
void combo_selected(gtkcombobox *widget, gpointer user_data) { int active_id=gtk_combo_box_get_active(gtk_combo_box(combo)); if(active_id!=-1) { //do real work... } }