QT-Day4

思维导图

作业:

头文件

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMessageBox>
#include <QTimerEvent>//定时器事件类
#include <QTime>
#include <QDebug>
#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();
void timerEvent(QTimerEvent *e);

private slots:
void on_pushButton_clicked();

private:
Ui::Widget *ui;
int id1;
int id2;
QTimer *timer1;
QTimer *timer2;
QTextToSpeech *spech;
};
#endif // WIDGET_H

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lab_back->setScaledContents(true);
    this->setAttribute(Qt::WA_TranslucentBackground);//去掉空白部分
    spech = new QTextToSpeech(this);


}

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


void Widget::on_pushButton_clicked()
{
    if(ui->lineEdit1->text()=="")
    {
        QMessageBox::information(this,"information","还没输入呢!",QMessageBox::Ok);
    }
    else
    {
        id1 = startTimer(1000);
    }
}

void Widget::timerEvent(QTimerEvent *e)
{
    if(e->timerId()==id1)
    {
        QTime system = QTime::currentTime();
        ui->lab1->setText(system.toString("hh:mm:ss"));
        ui->lab1->setAlignment(Qt::AlignCenter);
        if(ui->lineEdit1->text()==ui->lab1->text())
        {
            id2 = startTimer(1000);
        }
    }

    if(e->timerId()==id2)
    {
        spech->say(ui->lab3->text());
        spech->say(ui->lab3->text());
        spech->say(ui->lab3->text());
        spech->say(ui->lab3->text());
        spech->say(ui->lab3->text());
    }
}
相关推荐
yanyanwenmeng19 分钟前
matlab基础
开发语言·算法·matlab
末央&35 分钟前
【C++】内存管理
java·开发语言·c++
不是仙人的闲人38 分钟前
Qt日志输出及QsLog日志库
开发语言·数据库·qt
八了个戒44 分钟前
【TypeScript入坑】TypeScript 的复杂类型「Interface 接口、class类、Enum枚举、Generics泛型、类型断言」
开发语言·前端·javascript·面试·typescript
梦想科研社1 小时前
【无人机设计与控制】四旋翼无人机轨迹跟踪及避障Matlab代码
开发语言·matlab·无人机
Yan-英杰1 小时前
Encountered error while trying to install package.> lxml
开发语言·python·pandas·pip·issue
卡卡_R-Python1 小时前
海洋气象编程工具-Python
开发语言·python
爱学习的真真子1 小时前
菜鸟也能轻松上手的Java环境配置方法
java·开发语言
豆本-豆豆奶1 小时前
23个Python在自然语言处理中的应用实例
开发语言·python·自然语言处理·编程语音
曳渔1 小时前
Java-数据结构-二叉树-习题(三)  ̄へ ̄
java·开发语言·数据结构·算法·链表