12.12作业

头文件
 

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimerEvent>
#include <QTime>
#include <QtTextToSpeech>

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_pushButton_clicked();

private:
    Ui::Widget *ui;
    int id;
    QTextToSpeech *speecher;
};
#endif // WIDGET_H

2源文件

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->label->setAlignment(Qt::AlignCenter);
    ui->lineEdit->setAlignment(Qt::AlignCenter);
    id=startTimer(1000);
    speecher = new QTextToSpeech(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);


}

Widget::~Widget()
{
    delete ui;
}

void Widget::timerEvent(QTimerEvent *e)
{
   if(e->timerId()==id)
   {
    QTime sys_time = QTime::currentTime();

    QString s = sys_time.toString("hh:mm:ss");

    ui->label->setText(s);
   }
    else
   {
       if(ui->lineEdit->text()==ui->label->text())
       {
           int i=5;
           while(i--)
           {
               speecher->say(ui->label_3->text());
           }
       }
   }
}


void Widget::on_pushButton_clicked()
{
    startTimer(1000);

}



 






 

相关推荐

  1. 1213

    2023-12-12 21:46:01       75 阅读
  2. Postgresql源码(121)事务状态中childXids的作用

    2023-12-12 21:46:01       47 阅读
  3. 作业..........

    2023-12-12 21:46:01       55 阅读
  4. AcWing 1211. 蚂蚁感冒

    2023-12-12 21:46:01       43 阅读
  5. AcWing 1221. 四平方和

    2023-12-12 21:46:01       35 阅读
  6. 1213:八皇后问题

    2023-12-12 21:46:01       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-12 21:46:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-12 21:46:01       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-12 21:46:01       82 阅读
  4. Python语言-面向对象

    2023-12-12 21:46:01       91 阅读

热门阅读

  1. 好题分享(1)

    2023-12-12 21:46:01       66 阅读
  2. ARM NEON加速介绍及使用示例

    2023-12-12 21:46:01       45 阅读
  3. 【设计模式】:单例模式

    2023-12-12 21:46:01       55 阅读
  4. AtCoder Beginner Contest 332

    2023-12-12 21:46:01       67 阅读
  5. 数论——质数与约数

    2023-12-12 21:46:01       57 阅读
  6. 关于Pytorch和Numpy中的稀疏矩阵sparse的知识点

    2023-12-12 21:46:01       282 阅读
  7. 判断上三角矩阵

    2023-12-12 21:46:01       58 阅读
  8. 谈谈你对线程安全的理解

    2023-12-12 21:46:01       55 阅读
  9. 一文了解 Go 方法

    2023-12-12 21:46:01       60 阅读
  10. 第二十五章 STL- 常用算法

    2023-12-12 21:46:01       55 阅读