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());
    }
}
相关推荐
ajassi20002 小时前
开源 C++ QT Widget 开发(十五)多媒体--音频播放
linux·c++·qt·开源
CodeCraft Studio2 小时前
PDF处理控件Aspose.PDF教程:使用 Python 将 PDF 转换为 Base64
开发语言·python·pdf·base64·aspose·aspose.pdf
零点零一2 小时前
VS+QT的编程开发工作:关于QT VS tools的使用 qt的官方帮助
开发语言·qt
lingchen19064 小时前
MATLAB的数值计算(三)曲线拟合与插值
开发语言·matlab
gb42152875 小时前
java中将租户ID包装为JSQLParser的StringValue表达式对象,JSQLParser指的是?
java·开发语言·python
一朵梨花压海棠go5 小时前
html+js实现表格本地筛选
开发语言·javascript·html·ecmascript
蒋星熠5 小时前
Flutter跨平台工程实践与原理透视:从渲染引擎到高质产物
开发语言·python·算法·flutter·设计模式·性能优化·硬件工程
翻滚丷大头鱼5 小时前
Java 集合Collection—List
java·开发语言
aramae6 小时前
C++ -- 模板
开发语言·c++·笔记·其他
胡耀超6 小时前
4、Python面向对象编程与模块化设计
开发语言·python·ai·大模型·conda·anaconda