Qt作业九

1、思维导图

2、作业

widget.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimer>
#include <QTime>
#include <QTimerEvent>
#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_start_clicked();

    void on_stop_clicked();

private:
    Ui::Widget *ui;
    int tId,tId1;
    QTextToSpeech *speaker;
};
#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);
    speaker=new QTextToSpeech(this);
    tId=startTimer(1000);//系统时间间隔器
}

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

void Widget::timerEvent(QTimerEvent *e)
{
    if(e->timerId()==tId)
    {
        //获取当前系统时间
        QTime sys_time = QTime::currentTime();
        //把系统时间转换成字符串
        QString s = sys_time.toString("hh-mm-ss");
        //将系统时间放入标签中
        ui->lock->setText(s);
        //居中显示
        ui->lock->setAlignment(Qt::AlignCenter);

        if(s == ui->ringlock->text())
        {
            ui->lable->setText("哎呦~你干嘛~~");
            tId1 = startTimer(1000);
        }
    }
    else if(e->timerId()==tId1)
    {
        speaker->say("鸡你太美鸡你实在是太美");
    }
}

void Widget::on_start_clicked()
{
    ui->lable->setEnabled(true);
}

void Widget::on_stop_clicked()
{
    speaker->stop();
}
相关推荐
饭小猿人4 分钟前
Flutter实现底部动画弹窗有两种方式
开发语言·前端·flutter
米优16 分钟前
qgis电子地图二次开发---比例尺
qt·qgis
aq553560016 分钟前
Workstation神技:一键克隆调试环境
java·开发语言
lly20240635 分钟前
框架:构建高效系统的基石
开发语言
skywalk81631 小时前
发现Kotti项目的python包Beaker 存在安全漏洞
开发语言·网络·python·安全
天天进步20152 小时前
Python全栈项目:从零构建基于 Django 的知识管理系统(KMS)
开发语言·python·django
珎珎啊2 小时前
Python3 迭代器与生成器
开发语言·python
凯瑟琳.奥古斯特2 小时前
C++变量与基本类型精解
开发语言·c++
喜欢吃鱿鱼2 小时前
DES加解密(附带解决转义问题)-VUE
开发语言·前端·javascript
愚者游世2 小时前
variadic templates(可变参数模板)各版本异同
开发语言·c++·程序人生·面试