使用Qt.labs.settings来存储应用的设置
来源:互联网 发布:浪迹网络课程 编辑:程序博客网 时间:2024/05/29 03:03
我在以前的文章中,讲述了如何使用U1db及SQLite offline storage API来存储应用的一些状态。在这篇文章中,我将介绍如何使用Qt.labs.settings来存储应用的状态。更加详细的介绍,请参阅链接。
首先,我们创建一个最简单的“App with Simple UI”模版应用,并修改文件“main.qml”如下:
import QtQuick 2.0import Ubuntu.Components 1.1import Qt.labs.settings 1.0/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "com.ubuntu.developer.liu-xiao-guo.settings" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(50) height: units.gu(75) Page { title: i18n.tr("Simple") Column { anchors.fill: parent anchors.centerIn: parent anchors.horizontalCenter: parent.center Label { text: "Please input a string below:" fontSize: "large" } TextField { id: myTextField text: settings.input placeholderText: "please input a string" onTextChanged: { settings.input = text } } Button { text: "Get category" onClicked: { console.log("settings category:" + settings.category); } } } Settings { id: settings property string input: "unknown" } Component.onDestruction: { settings.input = myTextField.text } }}
记得这里我们一定要加入Qt.labs.settings。我们首先绑定myTextField的值为settings中的input。在程序退出的时候,我们通过如下的方式进行存储:
Component.onDestruction: { settings.input = myTextField.text }
在我们的应用中,我们使用如下的方法。每当myTextField变化时,我们就存一下。这依赖于我们最终程序的需求是什么样的。
TextField { id: myTextField text: settings.input placeholderText: "please input a string" onTextChanged: { settings.input = text } }
运行我们的应用,我们会发现,当我们修改myTextField中的值,并退出后。下次启动时,可以看到,上次输入的值被读取,并存放于myTextField中。
整个测试的源码在 bzr branch lp:~liu-xiao-guo/debiantrial/settingsqml
0 0
- 使用Qt.labs.settings来存储应用的设置
- 使用SQLite offline storage API来存储应用的设置
- WinForm:应用程序设置(Application Settings)的应用
- Bluemix云平台实践:使用Bluemix Labs Catalog来创建应用(1)
- Bluemix云平台实践:使用Bluemix Labs Catalog来创建应用(2)
- Qt Labs
- Qt中使用 setStyleSheet来设置图形界面的外观
- 使用HDFS来进行线上应用的文件存储
- ios开发中 应用设置的简单开发 (Settings.bundle)
- ios开发中 应用设置的简单开发 (Settings.bundle)
- Django应用的设置对象django.conf.settings详解
- C#中使用设置(Settings.settings) Properties.Settings.Default .
- C#中使用设置(Settings.settings) Properties.Settings.Default .
- Qt 5.6 的 Qt.labs.controls 在安卓上效果
- 保存程序的设置 Settings.settings
- Settings Bundle -- iPhone应用设置简单分析
- Settings.System的使用
- django框架的settings设置
- jquery的stop()
- 前端面试题目及答案(欢迎拍砖)
- MySQL中OPTIMIZE TABLE的作用
- 开博第一篇
- 第八周项目6—本月有几天?
- 使用Qt.labs.settings来存储应用的设置
- startx 及xinit 介绍
- Cocos2d-x-2.2.1如何创建工程,以及如何将工程独立出来
- Java 正则表达式
- Android中JNI的使用方法
- 人工智能:一种现代方法 第四版 翻译序言
- 十三行史上最细的介绍 广州服装定制
- javascript深入理解js闭包
- 你还在问android横竖屏切换的生命周期?