[Solved] Error using states to change between pages
-
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: 420property 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 ?
-
It's working :) , I changed
@onGameclick: root.activeState: "game"@
to
@onGameclick: root.activeState = "game"@
-
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? -
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