• day3_QT


    1、文件保存

    请添加图片描述

    2、始终事件 -闹钟

    widget.h

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #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 *event) override;
    
    private slots:
        void on_startBtn_clicked();
    
        void on_overBtn_clicked();
    
    private:
        Ui::Widget *ui;
    
        int timer_id_show;  //定时器的id号
    
        int timer_id_start;
    
        QString inputTime;
    
        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
    • 40
    • 41
    • 42
    • 43

    widget.c

    #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        //启动时的定时器时间  用于左上时间的显示
        timer_id_show = this->startTimer(1000);
    
        speecher = new QTextToSpeech(this);
    
        ui->setupUi(this);
    }
    
    
    //定时器事件处理
    void Widget::timerEvent(QTimerEvent *event)
    {
        QString timeStr;
        if(event->timerId() == timer_id_show)
        {
            /*ui界面优化*/
            ui->timeLabel->setAlignment(Qt::AlignCenter);
            //启动程序时候,就要显示表
            QTime sys_t = QTime::currentTime();
            timeStr =  sys_t.toString("hh:mm:ss");
            ui->timeLabel->setText(timeStr);
    
        }
        if(event->timerId() == timer_id_start)
        {
            //处理时间相同否?
            if(inputTime == timeStr )
            {
                //时间到
                QString str = ui->text->toPlainText();
                speecher->say(str);
            }
    
        }
    }
    
    
    void Widget::on_startBtn_clicked()
    {
        inputTime = ui->inTime->text();
        timer_id_start = this->startTimer(1000);
    }
    
    
    void Widget::on_overBtn_clicked()
    {
        this->killTimer(timer_id_start);
        ui->inTime->clear();
    }
    
    Widget::~Widget()
    {
        this->killTimer(timer_id_show);
        delete ui;
    }
    
    • 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
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
  • 相关阅读:
    ZKP5.2 PLONK IOP
    kotlin的by lazy
    关于org.tio.core.udp的UDP交互使用示例
    [postgresql]postgresqlg使用enerate_series() 函数补全统计
    uni单选radio
    JavaWep开始
    【Numpy总结】第七节:Numpy常用的函数(汇总所有函数,收藏这一篇就OK啦~)
    AtCoder Beginner Contest 237 VP补题
    二手车交易管理系统
    [carla入门教程]-6 小项目:基于carla-ros-bridge构建一个小型比赛赛道
  • 原文地址:https://blog.csdn.net/weixin_45790676/article/details/133047364