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

ok1hlm at centrum.cz ok1hlm at centrum.cz
Mon Dec 29 14:45:52 UTC 2014


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


More information about the Devel mailing list