qml (五)timer

打印 上一主题 下一主题

主题 1022|帖子 1022|积分 3066

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. Window {
  5.     width: 640
  6.     height: 480
  7.     visible: true
  8.     title: qsTr("Hello World")
  9.     property int timeCount:0
  10.     Text {
  11.         id: txt1
  12.         text: qsTr("text")
  13.         anchors.centerIn: parent
  14.     }
  15.     Timer{
  16.         id: timer1
  17.         interval: 1000
  18.         // running: false
  19.         repeat: true
  20.         triggeredOnStart: true  // 定时器一启动就触发一次
  21.         onTriggered:{
  22.             timeCount ++
  23.             txt1.text = "time count " + timeCount
  24.         }
  25.     }
  26.     Column{
  27.         id:idRow
  28.         spacing: 10
  29.         Button{
  30.             id: btn1
  31.             text: "start"
  32.             onClicked: {
  33.                 timer1.start()
  34.             }
  35.         }
  36.         Button{
  37.             id: btn2
  38.             text: "pause"
  39.             onClicked: {
  40.                 timer1.stop()
  41.             }
  42.         }
  43.         Button{
  44.             id: btn3
  45.             text: "restart"
  46.             onClicked: {
  47.                 timer1.restart()
  48.             }
  49.         }
  50.         Component.onCompleted: {
  51.                    console.log("row width = ",width, " row height = ", height);
  52.                }
  53.     }
  54. }
复制代码
timer 的interval表现的是时间隔断,ontrigger表现定时器到达时间隔断后的回调函数。repeate是表现start后ontrigger回调一次照旧连续回调。timer.start()表现开启定时器,restart()表现重新开启定时器,如果开没到达interval时间,则重新计时。stop()函数表现暂停。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

科技颠覆者

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表