#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
//label1 时间
s=new QTimer(this);
s->start(1000);
//两个qt5连接
//第一个连接为 timeout信号和timeout函数连接来在label1中显示时间
connect(s,&QTimer::timeout,this,&Widget::timeout_slot);
//第二个连接为 emit信号和timeout函数连接,当按钮“启动”按下emit信号释放,在timeout函数中
//随时间一起判断闹钟时间是否相等
connect(this,&Widget::my_signal,&Widget::timeout_slot);
ui->lineEdit->setPlaceholderText("时间");
//语言播报
speecher=new QTextToSpeech(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e){
QTime sys_time=QTime::currentTime();
QString s=sys_time.toString(("hh::mm::ss"));
ui->label->setText(s);
ui->label->setAlignment(Qt::AlignCenter);
}
void Widget::timeout_slot(){
QTime sys_time=QTime::currentTime();
QString s=sys_time.toString("hh::mm::ss");
ui->label->setText(s);
ui->label->setAlignment(Qt::AlignCenter);
if(ui->lineEdit->text()==s){
for(int i=0;i<5;i++){
speecher->say(ui->label3->text());
}
}
}
void Widget::on_pushButton_clicked()
{
if(ui->pushButton->text()=="启动"){
ui->pushButton->setText("取消");
emit this->my_signal();
}else if(ui->pushButton->text()=="取消"){
ui->pushButton->setText("启动");
ui->lineEdit->setText("");
}
}