qt 5.1.2使用QML中的Settings存储一些状态,然后下次进来使用Component.onCompleted初始化的时候,获取到的Settings里面的设置值还是默认的,但是我按钮点击的时候获取的是上一次存储下来的,为什么在初始化Component.onCompleted的时候Setting内的属性会是最初始值,我要怎么做才能在Component.onCompleted中获取到上一次设置的值
ApplicationWindow {
visible: true
width:1920
height: 1080
Settings {
id: settings
fileName: "C:\\settings.ini"
//语言
property int languageType: 1
}
Component.onCompleted:{
//初始化 打印的为默认的1
console.log("Component.onCompleted ==="+(settings.languageType))
}
Button{
onClicked: { //界面出来以后我点击打印的是0 是我上一次保存的值
console.log("button onClicked====="+(settings.languageType))
}
}
}
仅供参考【Qt : Setting应用程序的数据保存和读取】,链接:http://t.zoukankan.com/xiaozoui11cl-p-12852575.html