12.12作业

2023-12-13 05:11:37

头文件
?

#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);

}



?






?

文章来源:https://blog.csdn.net/sleepkewu/article/details/134957687
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。