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

}
相关推荐
Quz3 天前
QML Hello World 入门示例
qt
xcyxiner6 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner7 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner7 天前
DicomViewer (添加模型类)3
qt
xcyxiner8 天前
DicomViewer (目录调整) 2
qt
xcyxiner8 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR0069 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术9 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园9 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob10 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio