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();
}
相关推荐
火云洞红孩儿16 小时前
告别界面孤岛:PyMe如何用一站式流程重塑Python GUI开发?
开发语言·python
叫我辉哥e117 小时前
新手进阶Python:办公看板集成ERP跨系统同步+自动备份+AI异常复盘
开发语言·人工智能·python
晚风吹长发17 小时前
初步了解Linux中的命名管道及简单应用和简单日志
linux·运维·服务器·开发语言·数据结构·c++·算法
C++ 老炮儿的技术栈17 小时前
不调用C++/C的字符串库函数,编写函数strcpy
c语言·开发语言·c++·windows·git·postman·visual studio
布局呆星17 小时前
闭包与装饰器
开发语言·python
fyzy17 小时前
C++写后端实现,实现前后端分离
开发语言·c++
huohuopro18 小时前
Mybatis的七种传参方式
java·开发语言·mybatis
Lee_SmallNorth18 小时前
变态需求之【角色不同访问数据库的用户不同】
java·开发语言·数据库
扶苏-su18 小时前
Java网络编程:InetAddress 详解
java·开发语言·网络
IOT-Power18 小时前
QT构建构建DataBus总线
开发语言·qt