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

QT【day3】

思维导图:
在这里插入图片描述

闹钟:

//widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include<QTimerEvent>
#include<QTimer>
#include<QTime>   //时间类
#include<QPushButton> //按钮类头文件
#include<QDebug>  //信息调试类,用于打印输出
#include<QTextBrowser>
#include<QMessageBox>
#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_activateBtn_clicked();void on_stopBtn_clicked();void my_slot();void on_timeLab_linkActivated(const QString &link);private:Ui::Widget *ui;int tId;QPushButton *activateBtn;QTextToSpeech *speecher;};
#endif // WIDGET_H
//widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);tId = startTimer(1000);//实例化一个语言播报员speecher = new QTextToSpeech(this);
}Widget::~Widget()
{delete ui;
}//定时器处理函数
void Widget::timerEvent(QTimerEvent *e)
{//判断是那个定时器到位if(e->timerId() == tId){//获取系统时间QTime sys_time = QTime::currentTime();//将时间转化为字符串QString t = sys_time.toString("hh-mm-ss");ui->timeLab->setText(t);ui->timeLab->setAlignment(Qt::AlignCenter);}
}//启动按钮对应的槽函数
void Widget::on_activateBtn_clicked()
{while(1){if(ui->timeLab->text() == ui->lineEdit->text()){int i = 0;while(i < 5){speecher->say(ui->txtLab->toPlainText());i++;}break;}}}//停止按钮对应的槽函数
void Widget::on_stopBtn_clicked()
{my_slot();
}//自定义槽函数
void Widget::my_slot()
{int ret = QMessageBox::information(this,"提示","您是否确定停止?",QMessageBox::Yes | QMessageBox::No,QMessageBox::No);if(ret == QMessageBox::Yes){ui->activateBtn->setEnabled(false);ui->txtLab->setEnabled(false);ui->timeLab->setEnabled(false);}else{ui->activateBtn->setEnabled(true);ui->txtLab->setEnabled(true);ui->timeLab->setEnabled(true);}
}
http://www.lryc.cn/news/97562.html

相关文章:

  • 模版模式和策略模式的区别
  • Github搭建个人博客全攻略
  • gensim conherence model C_V 值与其他指标负相关BUG
  • QT DAY3
  • TortoiseGit(小乌龟)使用问题总结
  • 106、Redis和Mysql如何保证数据一致
  • SpringBoot+jasypt-spring-boot-starter实现配置文件明文加密
  • k8s核心概念
  • opencv 处理的视频 保存为新视频 ,新视频 无法读取
  • 《golang设计模式》第一部分·创建型模式-02-原型模式(Prototype)
  • SpringCloudAlibaba微服务实战系列(一)Nacos服务注册发现
  • 23.7.27 牛客暑期多校4部分题解
  • Ubuntu 20.04 安装教程
  • 如何评判算法好坏?复杂度深度解析
  • 【HashMap】2352. 相等行列对
  • 如何声明静态方法 和 实现?
  • 哈工大计算机网络课程局域网详解之:无线局域网
  • 系统集成|第六章(笔记)
  • MySQL主从复制环境部署
  • day42-servlet下拉查询/单例模式
  • docker中设置容器健康检查
  • azure-cognitiveservices-speech api error while using with AWS Lambda
  • 系统集成项目管理工程师挣值分析笔记大全
  • TCP 协议【传输层协议】
  • Golang 中的 time 包详解(二):time.Duration
  • Linux 学习记录58(ARM篇)
  • 【一文搞懂】—带霍尔编码器的直流有刷减速电机
  • 滴水逆向三期笔记与作业——02C语言——05 正向基础/05 循环语句
  • Python抓取分享页面的源代码示例
  • linux安装nginx遇到的报错