QTday4作业

思维导图:

QTday4作业_第1张图片

widget.h:

#ifndef WIDGET_H
#define WIDGET_H

#include 
#include 
#include 
#include 
#include 
#include 

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

private:
    Ui::Widget *ui;
    QTextToSpeech *speech;
    int id;
    int secid;
};

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

    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowFlag(Qt::FramelessWindowHint);

    id = startTimer(1000);//启动定时器

    speech = new QTextToSpeech(this);
}

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

void Widget::timerEvent(QTimerEvent *e)
{


    if(e->timerId() == id)
    {
        QTime sys_time = QTime::currentTime();
        ui->syslabel->setText(sys_time.toString("hh:mm:ss"));
    }else if(e->timerId() == secid)
    {
        if(ui->syslabel->text() == ui->lineEdit->text())
        {

            //qDebug() << ui->textlabel->text();
            int i = 0;
            while(i<10)
            {
                speech->say(ui->textlabel->text());
                i++;
            }
            killTimer(secid);
        }
    }
}



void Widget::on_pushButton_clicked()
{
    secid = startTimer(1000);
}

 效果图:

QTday4作业_第2张图片

你可能感兴趣的:(c++,c语言)