您的位置:首页 > 编程语言 > Qt开发

QML用Qt.labs.settings实现保存用户设置

2017-04-21 13:25 190 查看
举个简单的例子:

main.cpp中设置程序信息

QGuiApplication::setApplicationName("Gallery");
QGuiApplication::setOrganizationName("QtProject");
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

在需要保存设置的qml中:

...
import Qt.labs.settings 1.0
...{
...
Settings {
id: settings
property string input: "Default"
}
TextInput{
width:200
height: 50
id: textInput
text: settings.input
}
Button{
anchors.top:textInput.bottom
text:"save"
onClicked: {
settings.input=textInput.text
}
}
...
}

程序关闭后,再次启动时信息还会在文本框内。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: