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());
    }
}
相关推荐
m0_7369191010 小时前
C++代码风格检查工具
开发语言·c++·算法
2501_9449347310 小时前
高职大数据技术专业,CDA和Python认证优先考哪个?
大数据·开发语言·python
黎雁·泠崖11 小时前
【魔法森林冒险】5/14 Allen类(三):任务进度与状态管理
java·开发语言
2301_7634724611 小时前
C++20概念(Concepts)入门指南
开发语言·c++·算法
TechWJ12 小时前
PyPTO编程范式深度解读:让NPU开发像写Python一样简单
开发语言·python·cann·pypto
lly20240612 小时前
C++ 文件和流
开发语言
m0_7066532312 小时前
分布式系统安全通信
开发语言·c++·算法
寻寻觅觅☆13 小时前
东华OJ-基础题-104-A == B ?(C++)
开发语言·c++
杨了个杨898213 小时前
memcached部署
qt·websocket·memcached
lightqjx13 小时前
【C++】unordered系列的封装
开发语言·c++·stl·unordered系列