#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//给定时器实例化对象
t1 =new QTimer(this);
//将定时器的timeout信号连接到自定义槽函数中
connect(t1,&QTimer::timeout,this,&Widget::on_timeout);
t1->start(1000);//每秒刷新一次
//给定时器实例化对象
t2 =new QTimer(this);
//将定时器的timeout1信号连接到自定义槽函数中
connect(t2,&QTimer::timeout,this,&Widget::on_timeout1);
}
Widget::~Widget()
{
delete ui;
}
//当前时间
void Widget::on_timeout()
{
//获取系统当前时间
QTime sys_t =QTime::currentTime();
//将系统时间转换成字符串
time =sys_t.toString("hh:mm");
//对字符串进行设置
if(showFlag)
{
time[2]=':';
showFlag=false;
}else
{
time[2]=' ';
showFlag =true;
}
//展示到ui界面
ui->lcd_colock->display(time);
}
void Widget::on_timeout1()
{
if( time==ui->textEdit_3->toPlainText())
{
//播报
speech =new QTextToSpeech(this);
speech->say(ui->textEdit->toPlainText());
}
}
//设定时间
void Widget::on_textEdit_3_copyAvailable(bool b)
{
if(ui->pushButton->text() == "启动")
{
// 获取用户输入的时间
QString strTime = ui->textEdit_3->toPlainText();
// 将时间转换成 QTime 格式
QTime setTime = QTime::fromString(strTime, "hh:mm:ss");
}
}
//启动
void Widget::on_pushButton_clicked()
{
t2->start(1000);
}
//关闭
void Widget::on_pushButton_2_clicked()
{
this->close();
}