#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
id=startTimer(1000);
speecher=new QTextToSpeech(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e)
{
if(e->timerId()==id)
{
QTime sys_time=QTime::currentTime();
ui->labeltime->setText(sys_time.toString("hh:mm:ss"));
}
if((ui->labeltime->text()==ui->lineEdit->text())&&flag==1)
{
qDebug()<<"闹钟触发";
int t=5;
while (t--)
{
speecher->say("懒虫,起床,好好学习,天天向上!");
}
}
}
void Widget::on_alarmbtn_clicked()
{
if(ui->alarmbtn->text()=="启动")
{
flag=1;
ui->alarmbtn->setText("关闭");
}
else
{
flag=0;
ui->alarmbtn->setText("启动");
}
}
01-11
于 2024-01-11 20:51:24 首次发布
本文介绍了如何在C++中使用Qt库创建一个带有计时器和闹钟功能的Widget类,实现实时时间显示和定时语音提醒。用户可以点击按钮启动或关闭闹钟功能。
摘要由CSDN通过智能技术生成