首页 > 其他 > 详细

Qt qml 单例模式

时间:2015-03-27 16:42:35      阅读:390      评论:0      收藏:0      [点我收藏+]

Qt qml 单例模式,没什么好说的,看代码吧。单例模式很适合做全局的配置文件。

 

【示例下载】

http://download.csdn.net/detail/surfsky/8539313

 

【以下是核心代码】

Global.qml

1 pragma Singleton
2 import QtQuick 2.0
3 QtObject {
4     property color bgColor: lightblue;
5     property int textSize: 20
6     property color textColor: "green"
7 }

qmldir

1 singleton Global Global.qml

TestSingleton.qml

 1 import QtQuick 2.0
 2 import "."  // 单例模式必须显式的调用qmldir文件
 3 Rectangle {
 4     width: 500
 5     height: 500
 6     color: Global.bgColor;
 7     Text{
 8         text: hello world
 9         font.pixelSize: Global.textSize  // 调用单例对象的属性
10         color: Global.textColor
11         anchors.centerIn: parent
12     }
13 }

 

Qt qml 单例模式

原文:http://www.cnblogs.com/surfsky/p/4372071.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!