• 嵌入式学习-qt-Day4


    嵌入式学习-qt-Day4

    一、思维导图

    在这里插入图片描述

    二、作业

    1.设计一个界面:显示系统时间;可以设置闹钟,在设置的时间到达后,显示五次字符串,并且语音播报。

    Wight.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 *event) override;
        int t1;//定时器1
        int t2;//定时器2
    private slots:
        void on_pushButton_clicked();
    private:
        Ui::Widget *ui;
        QTextToSpeech *speech;//语音播报者
    };
    #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

    Wight.cpp

    #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
        t1 = startTimer(1000);//启动定时器t1
        speech = new QTextToSpeech(this); //实例化语音播报者
    }
    
    //定时器函数
    void Widget::timerEvent(QTimerEvent *e)
    {
        //系统时间
        if (e->timerId() == t1)
        {
            QTime sys_time = QTime::currentTime();
            QString s = sys_time.toString("hh:mm:ss");
            ui->sys_time->setText(s);
        }
        //闹钟
        if ((e->timerId() == t2))
        {
            for(int i = 0;i < 5; i++){
                ui->label->setText("好好学习天天向上");
                speech->say(ui->label->text());
            }
            killTimer(t2);//关闭定时器2
        }
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    void Widget::on_pushButton_clicked()
    {
        QTime sys_time = QTime::currentTime();
        QTime alarm_time = ui->timeEdit->time();
        int current_s = sys_time.hour()*3600 + sys_time.minute()*60 + sys_time.second();
        int alarm_s = alarm_time.hour()*3600 + alarm_time.minute()*60 + alarm_time.second();
    
        t2 = startTimer((alarm_s - current_s)*1000);//启动定时器2
    
        ui->label->setText("设置成功!");
    }
    
    • 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

    运行结果
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    PyTorch檔案生成機制中的FileManager.write_with_template
    机器学习介绍(上)
    获取当前OA地址JSP处理判断逻辑
    【算法】删除有序数组中的重复项
    【AI数学】余弦相似性(含python实现)
    数据结构与算法之美笔记05(链表)
    PostgreSQL 17新特性之登录事件触发器
    振弦采集模块测量振弦传感器的流程步骤?
    常用类和内部类总结
    linux中的lo介绍及作用(回环接口 回环IP)
  • 原文地址:https://blog.csdn.net/weixin_51597107/article/details/136263110