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);
}
相关推荐
沿着路走到底34 分钟前
python 基础
开发语言·python
沐知全栈开发1 小时前
C# 委托(Delegate)
开发语言
feiyangqingyun1 小时前
有难度哦/Qt基于通用地图组件实现航迹规划和模拟/动态标注轨迹线/带序号和方向箭头指示
qt·航迹规划和模拟
江公望2 小时前
Qt qmlRegisterSingletonType()函数浅谈
c++·qt
HyEISN2 小时前
关于 Qt 6.10.0 中 FolderListModel 返回 undefined 路径
qt
任子菲阳2 小时前
学Java第三十四天-----抽象类和抽象方法
java·开发语言
csbysj20203 小时前
如何使用 XML Schema
开发语言
R6bandito_3 小时前
STM32中printf的重定向详解
开发语言·经验分享·stm32·单片机·嵌入式硬件·mcu
earthzhang20213 小时前
【1007】计算(a+b)×c的值
c语言·开发语言·数据结构·算法·青少年编程
江公望3 小时前
Qt QtConcurrent使用入门浅解
c++·qt·qml