stackView.push(component,{}) property applying order
Unsolved
QML and Qt Quick
-
I have tried use new Controls 2 way to manage life of dynamical generated components and catch strange applying order (at least for me). Here is my code:
Page1.qml:
import QtQuick 2.7 Rectangle { property alias index: combo1.index property string value: "" onValueChanged: { combo1.setValue(value) } MyCombo{ id: combo1 anchors.fill: parent model: ["zero","one","two","three"] } }
MyCombo.qml
import QtQuick 2.7 import QtQuick.Controls 1.4 Item { property alias index: combo.currentIndex onIndexChanged: { console.log("index changed") } property alias model: combo.model onModelChanged: { console.log("model changed") } ComboBox{ id: combo anchors.centerIn: parent width: parent.width-10 } function setValue(val){ var index = model.indexOf(val) // HOTFIX: val==="" was added because ComboBox actually don't want to set "" as curretnText from code // Reason for this function: https://bugreports.qt.io/browse/QTBUG-51698 if (index === -1 || val === ""){ input.editText = val } else{ input.currentIndex = index } } }
How I load:
var component = Qt.createComponent("Page1.qml") stackView.push(component,{index:2}) // result is good, but I can see that index was applied before model in console stackView.push(component,{value:"two"}) // here catch error qrc:/MyCombo.qml:21: TypeError: Property 'indexOf' of object 1 is not a function
I am a bit confused this fact. Of course, I have fix it in my code by manual applying model before index, but I don't know does it bug and should I create bug report or it is just sprcific feature