GNOME Bugzilla – Bug 555560
gtk_combo_box_set_active fails with no model
Last modified: 2018-05-02 14:34:51 UTC
The function gtk_combo_box_set_active produces warnings if the model is unset, because it tries to work with a NULL model. This results in an 'object' test failing. It would seem that _set_active should just do nothing if there is no model.
Created attachment 120190 [details] [review] Bail out if the model is unset This patch implements a check whether the model is NULL, and to return early in that case.
(In reply to comment #1) > Created an attachment (id=120190) [edit] > Bail out if the model is unset > > This patch implements a check whether the model is NULL, and to return early in > that case. Hm, a better fix here would be to store the index internally and set it again once the model is set, so the ::model and ::active properties can be truely set out of order. But still, the attached patch at least avoids a bogus warning.
Created attachment 120289 [details] [review] Store the index in case the model is set afterwards This patch implements, as suggested, saving the index in the case where the model is not *yet* set and applies it when the model is set. Incidentally I found bug 466715 which should be fixed with this patch.
Created attachment 120290 [details] A standalone testcase This testcase creats a combo box, sets the active item and creates and sets a model afterwards. Without the above patch it outputs "active: 1 == -1", with the patch it will actually output "active: 1 == 1" regardless of when the index is set.
2008-12-13 Matthias Clasen <mclasen@redhat.com> Bug 555560 – gtk_combo_box_set_active fails with no model * gtk/gtkcombobox.c: Allow out-of-order setting of model and active. Patch by Christian Dywan
This patch is bogus. I'm going to revert it unless someone cries very loudly and with good reasons. The patch is bogus for the following reasons: 1) Setting the active row is supposed to work on the _current_ model. 2) Setting the active row and then setting the model fails if there is already a model set. 3) gtk_combo_box_get_active() does not return the value set by this function. 4) This function does not fix a real-world problem.
Oh yeah: 5) No other API in GTK behaves like this.
(In reply to Benjamin Otte (Company) from comment #6) > This patch is bogus. I'm going to revert it unless someone cries very loudly > and with good reasons. I guess we're too late now and GTK+ 3 has to keep this oddity. :( GTK+ 4, however... shall we bin it?
At this point, unless anyone objects, I think we should revert this in GTK+ 4. On the slim chance that any real code relies on this, that can be revealed, and it's probably that code that needs fixed, not GtkComboBox. As Benjamin said, this doesn't seem to solve a real problem, i.e. this rationale is very unconvincing: (In reply to Tim Janik from comment #2) > Hm, a better fix here would be to store the index internally and set it > again once the model is set, so the ::model and ::active properties can be > truely set out of order. But still, the attached patch at least avoids a > bogus warning. It's not at all evident why it is desirable to set these properties out of order, given that :active depends on :model. The warning does not seem bogus at all: we shouldn't be able to set an active item index if we have no model to get it from. (In reply to Christian Dywan from comment #0) > This results in an 'object' test failing. Which test? If still applicable, we should fix *that*, instead of setting a very strange precedent in GtkComboBox just to quiet it.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/300.