QTDAY4

#include "widget.h"
#include "ui_widget.h"

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

    id=startTimer(1000);

    speecher=new QTextToSpeech(this);
}

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

void Widget::timerEvent(QTimerEvent *e)
{
    if(e->timerId()==id)
    {
        QTime sys_time=QTime::currentTime();//获取系统时间
        QString s=sys_time.toString("hh:mm:ss");//类型转换
        ui->lab1->setText(s);//放入
        ui->lab1->setAlignment(Qt::AlignCenter);//居中显示
    }
    else if(e->timerId()==id1)
    {
        if(ui->edit1->text()==ui->lab1->text())
        {
            for(int i=0;i<5;i++)

            {
                speecher->say(ui->lab3->text());
            }
        }
    }
}


void Widget::on_btn1_clicked()
{
    if(ui->btn1->text()=="启动")
    {
        id1=startTimer(1000);

        ui->btn1->setText("关闭");
    }
    else
    {   killTimer(id1);
       // ui->edit1->clear();
        ui->btn1->setText("启动");
    }
}

QTDAY4_第1张图片

你可能感兴趣的:(c++)