After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 555560 - gtk_combo_box_set_active fails with no model
gtk_combo_box_set_active fails with no model
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkComboBox
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2008-10-08 14:52 UTC by Christian Dywan
Modified: 2018-05-02 14:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Bail out if the model is unset (428 bytes, patch)
2008-10-08 14:54 UTC, Christian Dywan
committed Details | Review
Store the index in case the model is set afterwards (1.41 KB, patch)
2008-10-09 17:12 UTC, Christian Dywan
committed Details | Review
A standalone testcase (887 bytes, text/plain)
2008-10-09 17:14 UTC, Christian Dywan
  Details

Description Christian Dywan 2008-10-08 14:52:10 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.
Comment 1 Christian Dywan 2008-10-08 14:54:02 UTC
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.
Comment 2 Tim Janik 2008-10-09 14:52:20 UTC
(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.
Comment 3 Christian Dywan 2008-10-09 17:12:04 UTC
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.
Comment 4 Christian Dywan 2008-10-09 17:14:52 UTC
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.
Comment 5 Matthias Clasen 2008-12-13 08:13:17 UTC
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

Comment 6 Benjamin Otte (Company) 2011-09-29 02:34:05 UTC
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.
Comment 7 Benjamin Otte (Company) 2011-09-29 02:34:50 UTC
Oh yeah:
5) No other API in GTK behaves like this.
Comment 8 Daniel Boles 2017-08-15 14:23:32 UTC
(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?
Comment 9 Daniel Boles 2018-03-23 17:02:11 UTC
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.
Comment 10 GNOME Infrastructure Team 2018-05-02 14:34:51 UTC
-- 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.