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. [SOLVED]Can't change state because "can't find variable"
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.2k 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.
  • L Offline
    L Offline
    Laipis
    wrote on 7 Oct 2011, 08:39 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 7 Oct 2011, 08:55 last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on 7 Oct 2011, 09:02 last edited by
        #3

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

        --
        Vasiliy

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Laipis
          wrote on 7 Oct 2011, 09:58 last edited by
          #4

          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.

          1 Reply Last reply
          0

          1/4

          7 Oct 2011, 08:39

          • Login

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