Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget), speecher(new QTextToSpeech(this))
{//设置时钟ui->setupUi(this);startTimer(1000);//文本框label居中对齐ui->label_2->setAlignment(Qt::AlignCenter);connect(this,&Widget::my_signal,this,&Widget::my_slot);
}Widget::~Widget()
{delete ui;
}void Widget::timerEvent(QTimerEvent* e)
{QTime sys_time = QTime::currentTime();QString t = sys_time.toString("hh:mm:ss");QString a = sys_time.toString("hh:mm");ui->time->setText(t);ui->time->setAlignment(Qt::AlignCenter);if(a == ui->alarmClock->text()){ui->voiceBox->setText("现在是北京时间"+a);emit my_signal();}
}void Widget::on_logIn_clicked()
{//未输入闹钟就启动if(ui->logIn->text() == "启动闹钟" && ui->alarmClock->text() == ""){qDebug() << "请输入闹钟时间\n";}if(ui->logIn->text() == "启动闹钟" && ui->alarmClock->text() != ""){//正常启动ui->logIn->setText("关闭闹钟");ui->voiceBox->setText("闹钟已启动");}else if(ui->logIn->text() == "关闭闹钟"){//关闭闹钟并清除闹钟ui->voiceBox->setText("闹钟已关闭");ui->alarmClock->clear();ui->logIn->setText("启动闹钟");}
}void Widget::my_slot()
{for (int i=0;i<5;i++){speecher->say(ui->voiceBox->text());}
}