问题
I have the following code (windowid in code below refers to the root element's id, Root element's width & height are same as device's width & height (i.e FullScreened)
Image{
id:tick1
source: "../../pics/tick.png"
width:0.0395*windowid.width
height:0.041*windowid.height
x: 0.4474*windowid.width
y: 99
visible: false
MouseArea{
anchors.fill: parent
onClicked: tick1.y = tick1.y + 20
}
Settings{
property alias yValue: tick1.y
}
}
The above code saves the y value of the image & ensure that the new y value will be stored and retrieved even if the application restarted to be the new image's y value, The above code works perfectly but if image's y value were initialized dynamically like this: y: 0.506*windowid.height
instead of y: 99
Settings element wont work.
It seems like when y value is dynamically used, Qt executes everything (including the Settings element) then it starts to calculate any dynamic values found specially if that value depends on something else which is also dynamic as well (i.e device screen, width & height varies from one device to another).
How this issue can be fixed using dynamic values with the Settings element ?
来源:https://stackoverflow.com/questions/30131705/storing-data-using-settings-element-in-qml