作业--day45

定时播放

cpp 复制代码
#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")));
}

思维导图

相关推荐
博笙困了2 小时前
AcWing学习——双指针算法
c++·算法
感哥2 小时前
C++ 指针和引用
c++
感哥13 小时前
C++ 多态
c++
沐怡旸19 小时前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River4161 天前
Javer 学 c++(十三):引用篇
c++·后端
感哥1 天前
C++ std::set
c++
侃侃_天下1 天前
最终的信号类
开发语言·c++·算法
博笙困了1 天前
AcWing学习——差分
c++·算法
青草地溪水旁1 天前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(2)
c++·设计模式·抽象工厂模式
青草地溪水旁1 天前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(1)
c++·设计模式·抽象工厂模式