作业--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")));
}

在这里插入图片描述

思维导图

在这里插入图片描述

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值