在界面上显示当前时间,再设置一个闹钟,到了时间就吱吱响(至少5遍)
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget),speecher(new QTextToSpeech(this))
{ui->setupUi(this);id = startTimer(1000);ui->alalb->setText("请输入定闹钟的时间:");}Widget::~Widget()
{delete ui;
}void Widget::timerEvent(QTimerEvent *e)
{if(e->timerId() == id){QTime systime = QTime::currentTime();QString t = systime.toString("hh:mm:ss");ui->timelb->setText(t);ui->timelb->setAlignment(Qt::AlignCenter);}else{if(ui->lineEdit->text() == ui->timelb->text()){for(int i =0 ; i<5 ; i++){ui->showlb->setText("吱");speecher->say(ui->showlb->text());}}}
}void Widget::on_pushButton_clicked()
{id2 = startTimer(1000);}