思维导图:
代码:
.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->stopBtn->setEnabled(false);
tId1=startTimer(1000);
// tId2
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_startBtn_clicked()
{
tId2=startTimer(500);
ui->textEdit->setEnabled(false);
ui->editLabel->setEnabled(false);
}
void Widget::on_stopBtn_clicked()
{
ui->CrueLabel->setEnabled(true);
ui->editLabel->setEnabled(true);
ui->startBtn->setEnabled(true);
//this->killTimer(tId2);
}
void Widget::timeEvent(QTimerEvent *e)
{
if(e->timerId()==tId1)
{
QTime sys_time=QTime::currentTime();
speecher =new QTextToSpeech;
QString t=sys_time.toString("hh:mm::ss");
ui->CrueLabel->setText(t);
ui->CrueLabel->setAlignment(Qt::AlignCenter);
}
if(e->timerId()==tId2)
{
if(ui->editLabel->text()==ui->CrueLabel->text())
{
// speecher=new QTextToSpeech(this);
speecher->say(ui->textEdit->toPlainText());
}
}
}
.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimerEvent>
#include <QTime>
#include <QDebug>
#include <QTextToSpeech>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
void timeEvent(QTimerEvent *e);
QTextToSpeech *speecher;
private slots:
void on_startBtn_clicked();
void on_stopBtn_clicked();
signals:
private:
Ui::Widget *ui;
int tId1;
int tId2;
};
#endif // WIDGET_H