1
有道云笔记
2
.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimerEvent>
#include <QTime>
#include <QTextToSpeech>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = nullptr);
~Widget();
void timerEvent(QTimerEvent *e);
private slots:
void on_btn1_clicked();
void on_Edit1_textChanged(const QString &arg1);
private:
Ui::Widget *ui;
int id;
QTextToSpeech *speecher;
};
#endif // WIDGET_H
.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
speecher = new QTextToSpeech(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e)
{
int n=6;
if(e->timerId()==id)
{
QTime sys_t=QTime::currentTime();
QString s=sys_t.toString("hh::mm::ss");
ui->lab1->setText(s);
ui->lab1->setAlignment(Qt::AlignCenter);
//判断是否相等
if(s==ui->lab2->text())
{
while(n>0)
{
speecher->say(ui->lab3->text());
n--;
}
}
}
}
void Widget::on_btn1_clicked()
{
if(ui->btn1->text()== "启动")
{
id=startTimer(1000);
ui->btn1->setText("关闭");
}
else
{
killTimer(id);
ui->btn1->setText("启动");
}
}
void Widget::on_Edit1_textChanged(const QString &arg1)
{
ui->lab2->setText(arg1);
}