
widget.h
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include
- #include
- #include
- #include
- #include
-
- QT_BEGIN_NAMESPACE
- namespace Ui { class Widget; }
- QT_END_NAMESPACE
-
- class Widget : public QWidget
- {
- Q_OBJECT
-
- public:
- 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();
- }