Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. stackView.push(component,{}) property applying order

stackView.push(component,{}) property applying order

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
stackview
1 Posts 1 Posters 908 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aknew85
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved