zoukankan      html  css  js  c++  java
  • Qt qml 单例模式

    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      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 }
  • 相关阅读:
    64最长和谐子序列(594)
    63找到字符串中所有字母异位词(438)
    62有效的数独(36)
    10.10
    9.27作业
    9.27
    9.26
    9.25
    9.18学习内容
    9.17作业
  • 原文地址:https://www.cnblogs.com/surfsky/p/4372071.html
Copyright © 2011-2022 走看看