[SOLVED]Can't change state because "can't find variable"



  • Hi,

    Another problem that I have is when I try to change a state:

    @
    Rectangle {
    width: 400
    height: 500

        Component{
        id: myComponent
    
            Item {
                id:myItem
                height: 50
                states: State {
                            name: "resizeMyItem";
                            PropertyChanges { target: myItem;
                            height: 100}
                                    }
                     }
    

    MouseArea {
    width: 79
    height: 69
    onClicked: {myItem.state = "resizeMyItem"}
    }@

    No issues when building this code but when I run it and click the mouse area, it says "ReferenceError: Can't find variable: myItem"

    I googled some state examples and comparing to them I can't see where the problem is?


  • Moderators

    I just saw that it might be case problem in your code.

    Maybe you have to write:
    @
    MouseArea {
    width: 79
    height: 69
    onClicked: {myItem.State = "resizeMyItem"}
    }@

    The only difference is that the first letter of "State" is now capitalized.



  • check your braces, seems like your item out of scope for MouseArea



  • Changing the "state" to "State" didn't help but I managed to call the state from inside the braces of "myComponent" so it works now. Thanks to both from help.


Log in to reply
 

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