1、思维导图
2、作业
widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QTimer>
#include <QTime>
#include <QTimerEvent>
#include <QTextToSpeech>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void timerEvent(QTimerEvent *e);private slots:void on_start_clicked();void on_stop_clicked();private:Ui::Widget *ui;int tId,tId1;QTextToSpeech *speaker;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);speaker=new QTextToSpeech(this);tId=startTimer(1000);//系统时间间隔器
}Widget::~Widget()
{delete ui;
}void Widget::timerEvent(QTimerEvent *e)
{if(e->timerId()==tId){//获取当前系统时间QTime sys_time = QTime::currentTime();//把系统时间转换成字符串QString s = sys_time.toString("hh-mm-ss");//将系统时间放入标签中ui->lock->setText(s);//居中显示ui->lock->setAlignment(Qt::AlignCenter);if(s == ui->ringlock->text()){ui->lable->setText("哎呦~你干嘛~~");tId1 = startTimer(1000);}}else if(e->timerId()==tId1){speaker->say("鸡你太美鸡你实在是太美");}
}void Widget::on_start_clicked()
{ui->lable->setEnabled(true);
}void Widget::on_stop_clicked()
{speaker->stop();
}