• QT day4


    在这里插入图片描述

    // widget.h
    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include 
    #include  //时间类
    #include  // 定时器事件类
    #include  // 定时器类
    #include  //
    
    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); // 定时器事件函数重写
    
    signals:
        void my_signal(); // 自定义信号函数
    
    private slots:
        void on_startBtn_clicked(); // 启动按钮对应的槽函数
    
    private:
        Ui::Widget *ui;
    
        int tId; // 定时器的Id
    
        QTextToSpeech* speecher; // 用QTextToSpeech实例化一个speecher对象
    };
    #endif // WIDGET_H
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    // widget.cpp
    #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
        tId = startTimer(1000); // 启动一个定时器, 延时1000毫秒
    
        ui->tipEdit->setAlignment(Qt::AlignCenter); // 文字居中显示
    
        speecher = new QTextToSpeech(this); // 给speecher初始化和申请空间
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::timerEvent(QTimerEvent *e)
    {
        if (e->timerId() == tId) // 判断是哪个定时器
        {
            QTime time = QTime::currentTime(); // 获取当前系统时间
            QString displayStr = time.toString("hh:mm:ss"); // 将time的类型转换为QString类型
            // 判断系统时间是否与输入的时间相等
            if (displayStr == ui->timeLab->text())
            {
                int num = 5;
                while (num--)
                {
                    speecher->say(ui->label->text()); // 把label中的文字转换成语音
                }
            }
            ui->displayLab->setText(displayStr);
            ui->displayLab->setAlignment(Qt::AlignCenter);
        }
    }
    
    
    void Widget::on_startBtn_clicked()
    {
        ui->timeLab->setText(ui->tipEdit->text());
        ui->timeLab->setAlignment(Qt::AlignCenter);
        ui->tipEdit->clear(); // 清空输入框
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    思维导图
    在这里插入图片描述

  • 相关阅读:
    SQL生成整年日期表(全)
    Java 如何让HashMap集合按照key进行排序呢?
    网络通信IO模型上
    什么是高防CDN?有什么优势?
    【机器学习】最大期望算法(EM)
    Vue 官方文档2.x教程学习笔记 1 基础 1.7 条件渲染
    四探循环依赖 → 当循环依赖遇上 BeanPostProcessor,爱情可能就产生了!
    sqlmap 执行后打开其它程序
    Mac下 allure的下载与配置
    【g2o】g2o学习笔记 BA相关
  • 原文地址:https://blog.csdn.net/m0_51235177/article/details/134441770