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

12月12日作业

设计一个闹钟

头文件

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QTimerEvent>
#include <QTime>
#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_btn_clicked();private:Ui::Widget *ui;int id1;  //定时器idint id2;  //闹钟idQTextToSpeech *speecher;
};
#endif // WIDGET_H

源文件

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);id1 = startTimer(1000);  //启动id1定时器speecher = new QTextToSpeech(this);
}Widget::~Widget()
{delete ui;
}//定时器超时时,自动执行的代码
void Widget::timerEvent(QTimerEvent *e)
{//判断定时器if(e->timerId() == id1){//获取系统时间QTime sys_time = QTime::currentTime();//将系统时间转换QString s = sys_time.toString("hh:mm:ss");//将取到的时间放入label1中ui->label1->setText(s);//居中显示ui->label1->setAlignment(Qt::AlignCenter);}else if(e->timerId() == id2){//每秒判断一次,时间相同时做出反应if(ui->edit->text() == ui->label1->text()){ui->label3->setText("只要学不死,就往死里学");for(int i = 0;i < 5;i++){speecher->say(ui->label3->text());}}}
}
//启动按钮按下后的进行处理的槽函数
void Widget::on_btn_clicked()
{id2 = startTimer(1000);  //启动id2定时器
}

效果演示

思维导图

http://www.lryc.cn/news/258625.html

相关文章:

  • 基于Python+WaveNet+MFCC+Tensorflow智能方言分类—深度学习算法应用(含全部工程源码)(二)
  • ​secrets --- 生成管理密码的安全随机数​
  • 宇视科技视频监控 main-cgi 文件信息泄露漏洞
  • 【数学建模】《实战数学建模:例题与讲解》第十一讲-因子分析、聚类与主成分(含Matlab代码)
  • Python查找列表中不重复的数字
  • 用docker创建jmeter容器,如何实现性能测试?
  • pytest-fixtured自动化测试详解
  • 计算机网络:应用层(一)
  • mybatis的快速入门以及spring boot整合mybatis(二)
  • lua基本语法使用
  • Git远程操作
  • 链表基础知识(一、单链表)
  • mysql的ON DELETE CASCADE 和ON DELETE RESTRICT区别
  • 如何快速将图片转为excel?
  • 元编程(Metaprogramming)
  • IEEE Transactions on Industrial Electronics工业电子TIE论文投稿须知
  • Linux--操作系统
  • HarmonyOS—实现UserDataAbility
  • Java实现插入排序及其动图演示
  • 设计模式——原型模式(创建型)
  • 深眸科技以机器视觉高性能优势,为消费电子行业提供优质解决方案
  • React setState()的两种书写方法对比
  • orb-slam2学习总结
  • 通过wireshark判断web漏洞的流量特征
  • Command ‘npm‘ not found, but can be installed with:sudo apt install npm 解决方案
  • 【Hadoop_04】HDFS的API操作与读写流程
  • go-zero开发入门之网关往rpc服务传递数据
  • Word插件-好用的插件-批量插入图片-大珩助手
  • 小程序域名SSL证书能用免费的吗?
  • selenium自动化(中)