Single QML page where children are unable to access other siblings



  • Hi there,

    I have a Simple Page with nested children and one of the child get data from C++ and want to set current Index of a Combobox, but i get undefidend error.

    I tried creating a alias property but failed miserably.

    Page{
    
    
    SomeOther{
    
    
    onC++Event{
    
    
    imnotaccessible.currentIndex = 0;
    undefied error
    
    }
    
    
    }
    
    ListView{
    
    header: Toolbar{
    
         ComboBox{
            
                id: imnotaccessible
    
         }
    
    }
    
    }
    
    }
    

    Please advise
    Thanks



  • @scotryder said in Single QML page where children are unable to access other siblings:

    A simple solution to the problem of access is to set an accessible property from your hierarchy with the id of the inaccessible item when you do have access to it.

    import QtQuick 2.9
    import QtQuick.Window 2.0
    import QtQuick.Controls 2.2
    
    Window
    {
        visible: true
        width: 200
        height: 200
        id:root
        property var anAccessibleItem
        Item
        {
            Rectangle
            {
                width: 100
                height: 100
                color: "red"
                MouseArea
                {
                    anchors.fill: parent
                    onClicked: console.info(anAccessibleItem.anInt++)
                }
            }
        }
        ListView
        {
            header: Item
            {
                Item
                {
                    id: imnotaccessible
                    property int anInt: 3
                    Component.onCompleted: root.anAccessibleItem = imnotaccessible
                }
            }
    
        }
    }
    


  • Cant thank you enough, it was a pain in the neck and you just solved in an instant.
    Thanks again :)



  • @scotryder please don't forget to mark your post as solved, thank you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.