I am currently working on a C based programm with a GTK UI. I currently have 6 Combo boxes without a set default value. The code is supposed to store the selected values of all comboboxes after a button press. The whole thing works fine if all 6 combo boxes have a selected value but how do i keep it from crashing once a combobox has no entry selected? In that case the whole thing just crashes.
You should check the return values of gtk_combo_box_get_active(), gtk_combo_box_get_active_iter() or gtk_combo_box_get_active_id(), depending on which one you are using.
gtk_combo_box_get_active() returns -1 if nothing is selected inside the combo box. Similarly, gtk_combo_box_get_active_iter() returns FALSE and gtk_combo_box_get_active_id() returns NULL.
You could also set_active(0) so there’s always something selected.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.