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

QT中闹钟的设置

在这里插入图片描述
.h文件

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QPushButton> //按钮
#include <QTextEdit> //文本
#include <QLabel>  //标签
#include <QLineEdit> //行编辑器#include <QTimerEvent> //定时器事件类头文件
#include <QDateTime> //日期时间类
#include <QtTextToSpeech/QTextToSpeech>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void timerEvent(QTimerEvent *event) override;
signals:void my_signal();
public slots:void btn1_slots(); //启动按钮槽函数void btn2_slots(); //关闭按钮槽函数private:Ui::Widget *ui;QPushButton *btn1;QPushButton *btn2;QLabel *lab;QTextEdit *text;QLineEdit *line;//实例化一个定时器指针//QTimer *timer;//定义一个定时器的idint timer_id;//设置一个播报员QTextToSpeech *speecher;
};
#endif // WIDGET_H

.cpp文件

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);//设置窗口的大小this->setFixedSize(540,410);//设置启动按钮btn1 = new QPushButton("启动",this);btn1->resize(70,50);btn1->move(340,100);connect(btn1,&QPushButton::clicked,this,&Widget::btn1_slots);//设置关闭按钮btn2 = new QPushButton("关闭",this);btn2->resize(btn1->size());btn2->move(btn1->x()+90,btn1->y());btn2->setEnabled(false);connect(btn2,&QPushButton::clicked,this,&Widget::btn2_slots);//设置定时闹钟lab = new QLabel("闹钟",this);lab->resize(310,150);lab->setStyleSheet("background-color:skyblue");//设置定的时间line = new QLineEdit(this);line->resize(160,50);line->move(btn1->x(),btn1->y()-70);//设置文本text = new QTextEdit(this);text->resize(540,270);text->move(lab->x(),lab->y()+180);text->setText("时间到了!");//设置播报员speecher = new QTextToSpeech;connect(this,&Widget::my_signal,[&](){speecher->say(this->text->toPlainText());});//定时器//timer = new QTimer(this);//将该定时的time信号连接到自定义的槽函数中//connect(timer,&QTime::timeout,this,&Widget::timeout_slots);
}Widget::~Widget()
{delete ui;
}void Widget::timerEvent(QTimerEvent *event)
{if(event->timerId()==timer_id){QDateTime sys_dt = QDateTime::currentDateTime();//获取当前系统日期时间this->lab->setText(sys_dt.toString("yyyy-MM-dd  hh:mm:ss"));if(sys_dt.toString("yyyy-MM-dd  hh:mm:ss") == this->line->text()){emit my_signal();}}
}void Widget::btn1_slots()
{//启动定时器timer_id=this->startTimer(1000);btn2->setEnabled(true);btn1->setEnabled(false);line->setEnabled(false);lab->setEnabled(false);}void Widget::btn2_slots()
{this->killTimer(timer_id);btn2->setEnabled(false);btn1->setEnabled(true);line->setEnabled(true);lab->setEnabled(true);speecher->stop();}
http://www.lryc.cn/news/157092.html

相关文章:

  • 【Redis】几款redis可视化工具(推荐Another Redis Desktop Manager)
  • 肖sir__设计测试用例方法之因果图07_(黑盒测试)
  • 李宏毅-21-hw3:对11种食物进行分类-CNN
  • 成集云 | 飞书审批同步金蝶云星空销售订单 | 解决方案
  • 06 科技英语|控制与优化学科词汇
  • 【网络教程】GitHub搜索技巧大揭秘
  • AUTOSAR LIN: LDF(LIN Description File)文件解析
  • Vue.js 报错:Cannot read property ‘validate‘ of undefined“
  • vue使用wangEditor
  • 网络编程、socket编程、多进程并发服务器
  • Elasticsearch:自动使用服务器时间设置日期字段并更新时区
  • 网络技术三:局域网基本原理
  • Fine-tuning Large Enterprise Language Models via Ontological Reasoning
  • 2023年全国职业院校技能大赛 高等职业教育组(信息安全管理与评估)正式赛题
  • 基于SSM的校园驿站管理系统
  • 分布式实时仿真系统-反射内存的应用
  • 【python技巧】替换文件中的某几行
  • 内网建自己的pip源
  • Vue 3的Diff算法相比Vue 2有哪些具体的改进?
  • 网络面试题整理
  • Liquid Studio 2023.2 Crack
  • 企业架构LNMP学习笔记8
  • 简单使用_matlab生成数据帧
  • uni-app语音转文字功能demo(同声传译)
  • vue2+element-ui批量导入方法并判断上传的文件是否为xls或xlsx
  • 【FPGA】通俗理解从VGA显示到HDMI显示
  • 【SpringMVC】参数传递与用户请求和响应
  • Android图形-Hardware Composer HAL
  • P1093 [NOIP2007 普及组] 奖学金
  • C#模拟PLC设备运行