Qt day5

思维导图:

作业:

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    speecher = new QTextToSpeech(this); //给播报者实例化空间
}

Widget::~Widget()
{
    delete ui;
}

//当定时器超时时自动执行
void Widget::timerEvent(QTimerEvent *e)
{
    static int num = 0;
    if(e->timerId()==id)
    {
        QTime sys_time = QTime::currentTime();
        QString t = sys_time.toString("hh:mm");

        ui->Lab1->setText(t);
        ui->Lab1->setAlignment(Qt::AlignCenter);

        //判断是否到闹钟时间
        if(ui->lineEdit->text() == t && num <3)
        {
            ui->textEdit->setText("警报");
            speecher->say(ui->textEdit->toPlainText());
            ++num;
        }
    }
}

//启动按钮对应的槽函数处理
void Widget::on_Btn1_clicked()
{
    //一钮多用
    if(ui->Btn1->text()=="启动")
    {
        //启动一个定时器
        id = startTimer(1000);
        ui->Btn1->setText("关闭");
    }
    else
    {
        //关闭定时器
        killTimer(id);
        ui->Btn1->setText("启动");
    }

}
相关推荐
leonkay37 分钟前
C# 特性(Attribute)——【1】基础讲解
开发语言·青少年编程·面试·c#·.net·个人开发
harmful_sheep1 小时前
java group by常见用法
java·开发语言·python
SKH.1 小时前
Linux软件编程(6)线程间通信
java·开发语言·数据库
whcyhhh1 小时前
头歌实践教学平台:数据科学与大数据技术导论(十六)
大数据·开发语言·python
萌动的小火苗1 小时前
数据结构面试题【无答案】
c语言·开发语言·数据结构·链表
宸津-代码粉碎机1 小时前
AI工程化高阶实战|从Demo到生产落地核心架构、全套源码与避坑指南
java·大数据·开发语言·人工智能·python·架构
XR1234567882 小时前
办公网自主创新建设怎么选?信创办公场景的选型逻辑
开发语言·php
郝学胜-神的一滴2 小时前
Effective Python 条款4:字符串格式化大乱斗
开发语言·网络·python·程序人生·软件工程
Ramble_Naylor3 小时前
只借不占:Rust 的引用与借用
开发语言·rust
FreeTinker3 小时前
Java文件服务器的技术选型与实现路径:从嵌入式工具到企业级系统
java·服务器·开发语言