赞
踩
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include <QWidget>
- #include <QTime>
- #include <QTimer>
- #include <QTimerEvent>
- #include <QPushButton>
- #include <QTextToSpeech>
-
- QT_BEGIN_NAMESPACE
- namespace Ui { class Widget; }
- QT_END_NAMESPACE
-
- class Widget : public QWidget
- {
- Q_OBJECT
-
- public:
- Widget(QWidget *parent = nullptr);
- ~Widget();
-
- private:
- Ui::Widget *ui;
- int id;
- QTextToSpeech *speecher;
-
- public:
- void timerEvent(QTimerEvent *e);
- private slots:
- void on_Btn1_clicked();
- };
- #endif // WIDGET_H
- #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)
- {
- QTime sys_time = QTime::currentTime(); //获取系统时间
- QString t = sys_time.toString("hh::mm::ss"); //转换
- ui->Lab1->setText(t); //显示
- if(ui->Lab1->text() == ui->Edit1->text())
- {
- ui->Lab3->setText("好好学习");
- speecher->say(ui->Lab3->text());
- }
- }
-
- void Widget::on_Btn1_clicked()
- {
- if(ui->Btn1->text() == "启动")
- {
- id = startTimer(1000); //让系统每隔一秒执行timerEvent函数
- ui->Btn1->setText("关闭");
- }else {
- killTimer(id);
- ui->Btn1->setText("启动");
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。