作业:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
,speecher(new QTextToSpeech(this))
{
ui->setupUi(this);
connect(this,&Widget::time_signal,this,&Widget::time_slot);
timeid = startTimer(1000);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e)
{
if(e->timerId()==timeid)
{
QTime sys_time = QTime::currentTime();
QString time = sys_time.toString("hh-mm-ss");
ui->time_lab->setText(time);
ui->time_lab->setAlignment(Qt::AlignCenter);
}
else if(e->timerId()==bombtimeid)
{
emit time_signal();
}
}
void Widget::on_pushButton_clicked()
{
bombtimeid = startTimer(1000);
}
void Widget::time_slot()
{
ui->res_lab->setText("Bomb has been planted");
ui->res_lab->setAlignment(Qt::AlignCenter);
if(ui->time_lab->text()==ui->lineEdit->text())
{
for (int i=0;i<5;i++)
{
speecher->say(ui->res_lab->text());
}
killTimer(bombtimeid);
}
}