Qt文档阅读笔记-Timer QML Type 官方解析与实例
发布日期:2021-06-30 10:58:50
浏览次数:2
分类:技术文章
本文共 1071 字,大约阅读时间需要 3 分钟。
目录
官方解析
Timer能够触发一个动作,或者在给定时间重复这个动作;
下面给出显示当前时间的代码,500毫秒刷新异常,这里是通过JS对象来获取当前时间!
import QtQuick 2.0 Item { Timer { interval: 500; running: true; repeat: true onTriggered: time.text = Date().toString() } Text { id: time } }
Timer和animation timer 是同步的。通常情况下animation timer被设置为60fps,所以Timer最好是设置为16ms。
如果Timer在运行的时候,它的某个属性被改变,那么他将会被重制,比如,一个时间间隔为1000ms的Timer被换成了500ms后,他将会从0重新开始。
博主例子
这里补充了官方的例子,运行截图如下:
目录结构如下:
main.cpp
#include#include int main(int argc, char *argv[]){ QApplication a(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl("qrc:/main.qml")); if(engine.rootObjects().isEmpty()){ return -1; } return a.exec();}
main.qml
import QtQuick 2.7import QtQuick.Controls 2.0ApplicationWindow { visible: true width: 400 height: 300 Timer{ interval: 1000 running: true repeat: true onTriggered: time.text = Date().toString() } Text{ id: time anchors.centerIn: parent font.pixelSize: 24 color: "#148014" }}
转载地址:https://it1995.blog.csdn.net/article/details/86182712 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月27日 05时56分51秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Linux创建进程的源码分析
2019-04-30
ubunut16.04的pip3出现问题,重新安装pip3
2019-04-30
how2heap-double free
2019-04-30
how2heap-fastbin_dup_consolidate
2019-04-30
orw_shellcode_模板
2019-04-30
[fmt+shellcode]string
2019-04-30
fmt在bss段(neepusec_easy_format)
2019-04-30
[double free] 9447 CTF : Search Engine
2019-04-30
python 函数式编程
2019-04-30
python编码
2019-04-30
scala maven plugin
2019-04-30
flink 1-个人理解
2019-04-30
redis cli
2019-04-30
redis api
2019-04-30
flink physical partition
2019-04-30
java 解析json
2019-04-30
java http请求
2019-04-30
tensorflow 数据格式
2019-04-30
tf rnn layer
2019-04-30