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

QT设置闹钟超时播报

头文件

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include<QTimerEvent>
#include<QTime>
#include<QTextToSpeech>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void timerEvent(QTimerEvent *e);private slots:void on_pushButton_clicked();private:Ui::Widget *ui;int id;int id1;QTextToSpeech *speecher;
};
#endif // WIDGET_H

测试文件

#include "widget.h"    
#include "ui_widget.h"  Widget::Widget(QWidget *parent)  : QWidget(parent) // 调用基类的构造函数,设置父对象  , ui(new Ui::Widget) // 实例化UI对象  , speecher(new QTextToSpeech(this)) // 实例化QTextToSpeech对象,并设置当前Widget为父对象  
{  ui->setupUi(this); / id = startTimer(1000); // 启动一个定时器,每隔1000毫秒(1秒)触发一次timerEvent  // 设置lineEdit的样式  ui->lineEdit->setStyleSheet("background-color: rgba(255, 255, 255, 150); border: 1px solid gray; border-radius: 5px;");  
}  Widget::~Widget()  
{  delete ui;   
}  // 当pushButton被点击时调用的槽函数  
void Widget::on_pushButton_clicked()  
{  id1 = startTimer(1000); // 启动另一个定时器,与id不同,用于不同的定时任务  
}  // 重写QWidget的timerEvent函数,处理定时器事件  
void Widget::timerEvent(QTimerEvent *e)  
{  // 检查是哪个定时器触发了事件  if(e->timerId()==id)  {  QTime sys_time=QTime::currentTime(); // 获取当前系统时间  QString t=sys_time.toString("hh--mm--ss"); // 将时间格式化为字符串  ui->label->setText(t); // 将时间字符串设置到label上  }  else if(e->timerId() == id1)  {  // 检查lineEdit中的文本是否与label中的文本相同  if(ui->lineEdit->text() == ui->label->text())  {  // 如果相同,则使用QTextToSpeech播放label_3中的文本5次  for(int i=0; i<5;i++)  {  speecher->say(ui->label_3->text());  }  }  }  
}


http://www.mrgr.cn/news/24576.html

相关文章:

  • 1.简述语言建模LM、统计语言建模SLM、神经语言模型NLM、预训练语言模型PLM、大语言模型LLM
  • 搜索功能技术方案
  • Linux——高流量 高并发(访问场景) 高可用(架构要求)
  • 源码编译 openblas for windows on arm
  • 串口接收不到数据之电阻虚焊bug分析思路
  • 微深节能 天车无人抓渣系统 格雷母线定位系统
  • C语言学习
  • React项目的开发前准备 以及 JSX 的基本使用
  • 非关系型数据库Redis
  • rocky8安装docker步骤
  • HCIE证书泛滥,曾经的“顶流”现在怎么了?
  • 【CAPL实战】解决调用LIN函数不生效问题
  • java实现策略模式
  • 路径规划 C++(Ⅱ)
  • 记录word转xml文件踩坑
  • 测测万用表?合宙功耗分析仪Air9000Air9000P齐出动
  • Plotly 画交互式3D图
  • 软件测试常用的7种方法,最后一个是升职加薪关键!(零基础小白转行IT互联网高效进阶)
  • 一文读懂DNS污染
  • Threejs之光线投射Raycaster交互