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();
}
相关推荐
QX_hao1 小时前
【Go】--反射(reflect)的使用
开发语言·后端·golang
inferno1 小时前
Maven基础(二)
java·开发语言·maven
我是李武涯1 小时前
从`std::mutex`到`std::lock_guard`与`std::unique_lock`的演进之路
开发语言·c++
史不了2 小时前
静态交叉编译rust程序
开发语言·后端·rust
读研的武3 小时前
DashGo零基础入门 纯Python的管理系统搭建
开发语言·python
Andy3 小时前
Python基础语法4
开发语言·python
但要及时清醒3 小时前
ArrayList和LinkedList
java·开发语言
孚亭3 小时前
Swift添加字体到项目中
开发语言·ios·swift
hweiyu003 小时前
Go、DevOps运维开发实战(视频教程)
开发语言·golang·运维开发