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();
}
相关推荐
虾球xz28 分钟前
CppCon 2015 学习:Reactive Stream Processing in Industrial IoT using DDS and Rx
开发语言·c++·物联网·学习
aischang1 小时前
统信桌面专业版如何使用python开发平台jupyter
开发语言·python·jupyter·统信uos
狐凄1 小时前
Python实例题:Python计算概率论
开发语言·python·概率论
Bardb1 小时前
02__C++的基本语法
c++·qt
15942315631 小时前
QT使用WxSQLite3打开加密数据库并查询
数据库·qt·sqlite
q567315232 小时前
分布式增量爬虫实现方案
开发语言·分布式·爬虫·python
勤奋的知更鸟2 小时前
LLaMA-Factory和python版本的兼容性问题解决
开发语言·python·llama-factory
CIb0la2 小时前
Ai自动补全编程工具:llama vscode
运维·开发语言·学习·测试工具·程序人生
1candobetter2 小时前
JAVA后端开发——多租户
java·开发语言
freyazzr2 小时前
C++八股 | Day3 | 智能指针 / 内存管理 / 内存分区 / 内存对齐
开发语言·c++