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("启动");
    }

}
相关推荐
一晌小贪欢几秒前
Python爬虫第7课:多线程与异步爬虫技术
开发语言·爬虫·python·网络爬虫·python爬虫·python3
ftpeak10 分钟前
《Cargo 参考手册》第二十二章:发布命令
开发语言·rust
luckyPian24 分钟前
学习go语言
开发语言·学习·golang
序属秋秋秋1 小时前
《Linux系统编程之入门基础》【Linux基础 理论+命令】(上)
linux·运维·服务器·ubuntu·centos·命令模式
祁同伟.1 小时前
【C++】多态
开发语言·c++
朱嘉鼎2 小时前
C语言之可变参函数
c语言·开发语言
北冥湖畔的燕雀5 小时前
C++泛型编程(函数模板以及类模板)
开发语言·c++
QX_hao7 小时前
【Go】--map和struct数据类型
开发语言·后端·golang
你好,我叫C小白7 小时前
C语言 循环结构(1)
c语言·开发语言·算法·while·do...while
Evand J8 小时前
【MATLAB例程】基于USBL和DVL的线性回归误差补偿,对USBL和DVL导航数据进行相互补偿,提高定位精度,附代码下载链接
开发语言·matlab·线性回归·水下定位·usbl·dvl