[SailfishDevel] [bug] Silica ComboBox.qml - can't set currentIndex after initialization

Andrey Kozhevnikov coderusinbox at gmail.com
Mon Jan 5 10:40:32 UTC 2015


yeah, i'm using _updating = false in my application also. This is the 
best workaround i found.

29.12.2014 19:45, ok1hlm at centrum.cz пишет:
> Hi,
>
> I've found a bug in ComboBox.qml used in Jolla phone. I wrote an application using pyotherside. During initialization, it populates combobox and sets the currentIndex to saved value. The problem is, that setting the currentIndex does nothing.
>
> ComboBox.qml uses weird timer to delay some tasks. When you change currentIndex before that timer is triggered, it ignores the change.
>
> Connections {
>      target: comboBox.menu ? comboBox.menu._contentColumn : null
>      onChildrenChanged: {
>          // delay the reload in case there are more children changes to come
>          if (!updateCurrentTimer.running) {
>              _updating = true
>              updateCurrentTimer.start()
>          }
>      }
> }
>
> VS.
>
> onCurrentIndexChanged: {
>      _currentIndexSet = true
>      if (_completed && !_updating) {
>          _updating = true
>          _updateCurrent(currentIndex, null)
>          _updating = false
>      }
> }
>
> My application does something like:
>
> function foo(result) {
>    for(var i=0; i<result.length; ++i)
>      combolistmodel.append({index:i, text:result[i]});
> }
> foo(['abc','def','foo','bar','baz']);
> // comboid._updating = 0; // REQUIRED WORKAROUND
> comboid.currentIndex=3;
>
> Whey I force the _updating to 'false', it works. Also if I set the correntIndex in a timer some time later, it works.
>
> I've tested following workaround:
>
> onCurrentIndexChanged: {
>      _currentIndexSet = true
>      if (_completed) {
>        if (updateCurrentTimer.running) {
>          var save_currentIndex = currentIndex;
>          updateCurrentTimer.stop()
>          updateCurrentTimer.onTriggered()
>          currentIndex = save_currentIndex;
>        }
>        if (!_updating) {
>          _updating = true
>          _updateCurrent(currentIndex, null)
>          _updating = false
>        }
>      }
> }
>
> But it still seems odd to me to use a timer in in a combobox.
>
> Whole reproducer: http://fpaste.org/164044/59940141/
> Code causing this problem: http://fpaste.org/163881/97171141/
> Tested workaround: http://fpaste.org/164045/85997614/
>
>
> Michal
> _______________________________________________
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to devel-unsubscribe at lists.sailfishos.org



More information about the Devel mailing list