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();
}
相关推荐
Omigeq10 分钟前
1.2.2 - 采样搜索算法(以RRT和RRT*为例) - Python运动规划库教程(Python Motion Planning)
开发语言·人工智能·python·机器人
m0_5312371744 分钟前
C语言-操作符进阶
c语言·开发语言
q1234567890981 小时前
FNN sin predict
开发语言·python
沐知全栈开发1 小时前
C++ 多态
开发语言
zihan03211 小时前
若依(RuoYi)框架核心升级:全面适配 SpringData JPA,替换 MyBatis 持久层方案
java·开发语言·前端框架·mybatis·若依升级springboot
先做个垃圾出来………1 小时前
Python字节串“b“前缀
开发语言·python
无限进步_1 小时前
21. 合并两个有序链表 - 题解与详细分析
c语言·开发语言·数据结构·git·链表·github·visual studio
神奇大叔2 小时前
Java 配置文件记录
java·开发语言
三水彡彡彡彡2 小时前
C++拷贝函数:const与引用的高效实践
开发语言·c++
悠闲蜗牛�2 小时前
深入浅出Spring Boot 3.x:新特性全解析与实战指南
开发语言·python