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] Error using states to change between pages
Forum Updated to NodeBB v4.3 + New Features

[Solved] Error using states to change between pages

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.6k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    john_god
    wrote on 17 May 2013, 00:06 last edited by
    #1

    Hi
    I'm tring to change between pages using states, in a small game. This is what I did:

    main.qml:
    @Rectangle {
    id: root
    ......
    PagePanel {
    id: pagepanel
    state: activeState
    }
    ......
    }@

    PagePanel.qml:
    @
    Item {
    id: root
    width: 360
    height: 420

    property string activeState: "game"
    states: [
        State {
            name: "menu"
            PropertyChanges {
                target: menuPage
                opacity: 1
                restoreEntryValues: true
            }
        },
    
        State {
            name: "game"
            PropertyChanges {
                target: gamePage
                opacity: 1
                restoreEntryValues: true
            }
    
        }
    
    ]
    
    
    PageMenu {
        id: menuPage
        anchors.fill: parent
        opacity: 0
      //  onGameclick: root.activeState: "game"
    }
    
    PageGame {
        id: gamePage
        anchors.fill: parent
        opacity: 0
       // onSunClick2: root.activeState: "menu"
    }
    

    }@

    The problem is if I uncomment lines 34 and 41, I get errors in main.qml line 4: @Type PagePanel unavailable
    PagePanel {
    ^ @

    and in lines 34 and 41 : @Expected token `;'
    onGameclick: root.activeState: "game"
    ^ @

    I very newbie in Qml, and I can't figure out to change states. I also don't know if this is the best approach, I read about pagestack wich perhaps would be another option ?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      john_god
      wrote on 19 May 2013, 23:44 last edited by
      #2

      It's working :) , I changed

      @onGameclick: root.activeState: "game"@

      to

      @onGameclick: root.activeState = "game"@

      1 Reply Last reply
      0
      • O Offline
        O Offline
        oosavu
        wrote on 21 May 2013, 06:13 last edited by
        #3

        hello!
        Good idea for container of many elements. this solve my problem.

        but why you use custom property "activeState"? this property is excessively.
        directly @onGameclick: root.state: "game"@ not working?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          john_god
          wrote on 21 May 2013, 10:49 last edited by
          #4

          Hi oosavu
          You are right I'm overcomplicating things. Using:

          @onGameclick: root.state = "game"@

          and in main.qml:

          @PagePanel {
          id: pagepanel
          state: "menu"
          }@

          works fine.
          Thank you

          1 Reply Last reply
          0

          4/4

          21 May 2013, 10:49

          • Login

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