定时器Timer

1、属性

interval:int  间隔时间

repeat:bool  是否重复

running:bool  查询当前状态

triggeredOnStart:bool  定时器开启即运行一次回调

2、信号

triggered  间隔时间到了发出此信号

3、方法

restart  重启

start  开启

stop  停止

4、列子,软件开启Text自减1

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

Window {
    id:main;
    visible: true
     360
    height: 360
    Text{
        id:text;
         50;
        height: 30;
        text: "10";
        color: "red";
        font.pixelSize: 30;
        horizontalAlignment: Text.AlignHCenter;
        property int count;
        anchors.centerIn: parent;
        Component.onCompleted: {
            text.count = 10000000;
        }
        Timer{
            id:timer;
            interval : 1000;
            repeat: true;
            triggeredOnStart: true;
            onTriggered: {
                if(text.count>0)
                {
                    text.text  = text.count;//这里说明了QML是弱类型,不需要int转String
                    text.count--;
                }
            }
            Component.onCompleted: {
                timer.start();
            }
        }
    }
}

原文地址:https://www.cnblogs.com/judes/p/9453512.html