1,
源代码:
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);speeror=new QTextToSpeech(this);id=startTimer(1000);//每隔一秒,自动调用timerEvent函数ui->textEdit->setText("一枪秒了,有什么好说的");}
void Widget::timerEvent(QTimerEvent *e){if(e->timerId()==id){QTime sys_time=QTime::currentTime();//获取系统时间QString t=sys_time.toString();//将系统时间转换为字符串ui->label_2->setText(t);//将字符串写入标签中ui->label_2->setAlignment(Qt::AlignCenter);//将标签的内容居中QString s=ui->lineEdit->text();//获取行编辑器的内容int i=0;//判断输入的时间和系统时间是否相等if(s==t){//循环读5次while(i<5){speeror->say(ui->textEdit->toPlainText());//文本编辑器的内容i++;}}}}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{if(ui->pushButton->text()=="启动"){id=startTimer(1000);//每隔一秒,自动调用timerEvent函数ui->pushButton->setText("关闭");}else{killTimer(id);//杀死定时器ui->pushButton->setText("启动");}}
2,思维导图