qt - Why doesn't a loader change its source on a state change if it has a default state specified? -


i have qml loader, can have 2 states. depending on state, different content loaded.

loader {     id: mainloader     anchors.fill: parent      state: "state1"      states:     [         state         {             name: "state1"             propertychanges {target: mainloader; source: "page1.qml"}         },          state         {             name: "state2"             propertychanges {target: mainloader; source: "page2.qml"}         }     ] } 

there 2 buttons elsewhere in application, have onclicked: mainloader.state = "state1" , onclicked: mainloader.state = "state2", respectively.

although state indeed changed (verified printing debug message in statechangescript), page 1 remains loaded @ times, page 2 never appeares.

what don't understand, following:

  • if don't assign default state (so remove state: "state1"), 2 buttons work, , both pages displayed correctly according button pressed. of course, before button pressed, loader empty.
  • if add asynchronous: true loader, 2 buttons work fine.

there several simple, not elegant solutions, example

  • just assign default source instead of default state. don't i'll have 3 states, including empty one, , need refer state of loader @ other places.
  • stick asynchronous operation.
  • use component.oncompleted: state = "state1" instead of state: "state1"

however, understand lies behind behavior. know properties not filled in order written in qml files, time press buttons, loader completed long time ago.


Comments

Popular posts from this blog

Multilayer CSV to filtered excel -

Listboxes in c# -

ios - Why must I define variables twice in the Header file? -