#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
,speecher(new QTextToSpeech(this))
{
ui->setupUi(this);
ui->label->setAlignment(Qt::AlignCenter);
id = startTimer(1000);
}
void Widget::timerEvent(QTimerEvent *e){
if(e->timerId() == id)
{
static int count=0;
QTime sys_time = QTime::currentTime();
QString t = sys_time.toString("hh:mm:ss");
QString text = ui->timedit->text();
if(text==t){
// QMessageBox::information(this, "提醒", "起床了!", QMessageBox::Ok);
while(1){
speecher->say(ui->label_3->text());
count++;
if(count==3){
break;
}
}
}
//将系统时间放入lab中
ui->label->setText(t);
//居中
ui->label->setAlignment(Qt::AlignCenter);
}
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
if(ui->pushButton->text() == "设定")
{
//启动定时器
id = startTimer(1000); //每个1s钟, 自动执行timerEvent()
//id2 = startTimer(2000);
//将按钮文本设置成“关闭”
ui->pushButton->setText("关闭");
}
else
{
//关闭定时器
killTimer(id);
//将按钮文本设置成“启动”
ui->pushButton->setText("设定");
}
}
qthome work
于 2024-09-12 07:38:40 首次发布