当前位置: 首页 > news >正文

Qt开发(5)——使用QTimer定时触发槽函数

实现效果

软件启动之后,开始计时,到达预定时间后,调用其他类的某个函数。

类的分工

BaseType:软件初始化的调用类
FuncType: 功能函数所在类

具体函数

// FuncType.h
class FuncType: public QObject
{Q_OBJECT
public:
public slots:void slotFunction();
};
// BaseType.h
#include <memory>
#include <QTimer>
#include "FuncType.h"class BaseType: public QObject
{Q_OBJECT
public:
private:QTimer* m_clearTimer;std::shared_ptr<FuncType> m_functype{nullptr};
};
// BaseType.cpp
FuncType::FuncType(QObject *parent) : QObject(parent)
{m_functype= std::make_shared<FuncType>();m_clearTimer = new QTimer(this);connect(m_clearTimer, &QTimer::timeout, m_functype.get(), &FuncType::slotFunction);m_clearTimer->start(1000); // 1s
}
http://www.lryc.cn/news/96207.html

相关文章:

  • 2023年JAVA最新面试题
  • (四)RabbitMQ高级特性(消费端限流、利用限流实现不公平分发、消息存活时间、优先级队列
  • Vue如何配置eslint
  • Elasticsearch查询文档
  • 面向对象编程:多态性的理论与实践
  • linux:filezilla root密码登陆
  • 在nginx上部署nuxt项目
  • 嵌入式linux通用spi驱动之spidev使用总结
  • 【Nodejs】Puppeteer\爬虫实践
  • Windows Active Directory密码同步
  • 安科瑞能源物联网以能源供应、能源管理、设备管理、能耗分析的能源流向为主线-安科瑞黄安南
  • FPGA设计时序分析一、时序路径
  • spring复习:(52)注解方式下,ConfigurationClassPostProcessor是怎么被添加到容器的?
  • 全国大学生数据统计与分析竞赛2021年【本科组】-B题:用户消费行为价值分析
  • 力扣1667. 修复表中的名字
  • 【设计模式】详解观察者模式
  • 用html+javascript打造公文一键排版系统8:附件及标题排版
  • 微服务体系<1>
  • M5ATOMS3基础02传感器MPU6886
  • vue 快速自定义分页el-pagination
  • 0-虚拟机补充知识
  • 如何将电机控制器添加到您的 ROS 机器人
  • ChatGPT统计“一到点就下班”的人数
  • Games101学习笔记 - 变换矩阵基础
  • Ubuntu18.04未安装Qt报qt.qpa.plugin could not load the Qt platform plugin xcb问题的解决方法
  • GPT4ALL私有化部署 01 | Python环境
  • GPT-AI 使用的技术概览
  • NoSQL-Redis持久化
  • 关于uniapp中的日历组件uni-calendar中的小红点
  • 【Nodejs】Node.js简介