作业--day45

定时播放

#include "mywidget.h"
#include "ui_mywidget.h"

MyWidget::MyWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MyWidget)
{
   
    ui->setupUi(this);
    ui->bg_lab->setPixmap(QPixmap(":/pictrue/shanChuan.jpg"));
    ui->bg_lab->setScaledContents(true);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowFlag(Qt::FramelessWindowHint);

    //系统时间定时器
    sys_time_id = startTimer(1000);

    speecher = new QTextToSpeech(this);

}

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

void MyWidget::timerEvent(QTimerEvent *e)
{
   
    if(e->timerId() == sys_time_id){
   
    
        QTime sys_time = QTime::currentTime();
        ui->sys_time_lab->setText(sys_time.toString("hh:mm:ss"));
        
    }else if(e->timerId() == clock_time_id){
   

        for(int i=0; i<2; i++){
   
            speecher->say(ui->msg_lab->text());
        }
        killTimer(clock_time_id);

    }
}

void MyWidget::on_exit_btn_clicked()
{
   
    this->close();
}

void MyWidget::on_start_btn_clicked()
{
   
    //播放语音定时器,msecsTo成员函数是用于计算时间差,单位为毫秒,fromString常用函数是用于根据字符串实例化一个QTime对象
    clock_time_id = startTimer(QTime::currentTime().msecsTo(QTime::fromString(ui->inp_time->text(), "hh:mm:ss")));
}

在这里插入图片描述

思维导图

在这里插入图片描述

相关推荐

  1. 代码随想录Day45

    2024-01-13 00:40:03       34 阅读
  2. 算法刷题day45

    2024-01-13 00:40:03       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-13 00:40:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-13 00:40:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-13 00:40:03       82 阅读
  4. Python语言-面向对象

    2024-01-13 00:40:03       91 阅读

热门阅读

  1. Leetcod面试经典150题刷题记录 —— 数学篇

    2024-01-13 00:40:03       40 阅读
  2. 五、K8S-StatefulSet(STS有状态服务)

    2024-01-13 00:40:03       41 阅读
  3. 【无标题】

    2024-01-13 00:40:03       55 阅读
  4. 【linux】history命令显示时间的例子

    2024-01-13 00:40:03       59 阅读
  5. Linux——命令行调整系统音量

    2024-01-13 00:40:03       57 阅读
  6. [leetcode] 3. 无重复字符的最长子串

    2024-01-13 00:40:03       47 阅读
  7. 开发React应用的多语言支持最佳实践

    2024-01-13 00:40:03       59 阅读