qt简易闹钟

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

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

    ui->stopBtn->setDisabled(true);

    this->setFixedSize(this->size());   //设置固定大小
    this->setWindowTitle("简易闹钟");

    //实例化一个播报员
    speecher = new QTextToSpeech(this);


}

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

void Widget::on_startBtn_clicked()
{
    ui->startBtn->setDisabled(true);
    ui->alarmEdit->setReadOnly(true);
    ui->textEdit->setReadOnly(true);
    ui->stopBtn->setEnabled(true);
    tId = startTimer(100);     //定义一个计时器
}

void Widget::timerEvent(QTimerEvent *e)
{

    //判断是哪个计时器就位
    if (e->timerId() == tId)
    {
        QTime sys_time = QTime::currentTime();  //获取系统时间

        //将系统时间转换为字符串
        QString t = sys_time.toString();

        //将字符串展示到label
        ui->timeLb->setText(t);

        alarmTime = ui->alarmEdit->text();  //获取闹钟时间

        //如果到了时间就开始播报
        if (t == alarmTime)
        {
            for (int i = 0; i < 10; i++)
            {

                speecher->say(ui->textEdit->toPlainText());
            }
        }



    }
}

void Widget::on_stopBtn_clicked()
{
    ui->startBtn->setDisabled(false);
    ui->alarmEdit->setReadOnly(false);
    ui->textEdit->setReadOnly(false);
    speecher->stop();
    killTimer(tId);
}
相关推荐
隐积15 小时前
3.1.7.Qt容器大家族(3):QVariant——万能盒子
开发语言·qt
名字还没想好☜18 小时前
Next.js ‘use client‘ 到底加在哪:Server/Client Components 边界与常见报错
开发语言·前端·javascript·react·next.js
初级代码游戏19 小时前
iOS开发 Swift 速记1:变量和基本数据类型
开发语言·ios·swift
酷在前行20 小时前
【R生态】PERMANOVA 进阶实战:距离选择、PERMDISP、两两比较与受限置换(保姆级教程)
开发语言·r语言
cxr82820 小时前
Graphify vs GitNexus vs CodeGraph — 三工具架构深度对比
开发语言·架构·知识图谱
废弃的小码农21 小时前
功能测试--Day07--Python编程基础
开发语言·python
fengci.1 天前
Microweber CMS 未授权路径穿越漏洞(CVE-2026-65694)
android·开发语言·前端·学习·php
程序员zgh1 天前
C++ 拷贝赋值运算符 详解
c语言·开发语言·c++
念何架构之路1 天前
restartmanager-重启管理子系统
java·开发语言
SomeB1oody1 天前
【RustyML入门】2.0. 经典机器学习
开发语言·后端·机器学习·rust·教程