• 20230903-闹钟


    app.cpp

    1. #include "app.h"
    2. #include "ui_app.h"
    3. int k1 = true;
    4. APP::APP(QWidget *parent):QWidget(parent),ui(new Ui::APP)
    5. {
    6. ui->setupUi(this);
    7. this->resize(380,300);
    8. this->setStyleSheet("background-color:cyan;");//设置样式
    9. speecher = new QTextToSpeech(this);
    10. T1 = new QTimer(this);//定时器T1
    11. T1->start(1000);
    12. connect(T1,&QTimer::timeout,this,&APP::time_slot1);
    13. connect(ui->SB1,&QPushButton::clicked,this,&APP::on_SB1start_clicked);
    14. connect(ui->SB2,&QPushButton::clicked,this,&APP::on_SB2stop_clicked);
    15. ui->Lb1->setAlignment(Qt::AlignCenter);//标签文本对齐方式 居中
    16. ui->Lb1->setFont(QFont("华文行楷",20));
    17. ui->Line1->setAlignment(Qt::AlignCenter);//对中
    18. ui->Line1->setFont(QFont("华文行楷",16));//字体
    19. ui->Text1->setAlignment(Qt::AlignCenter);//对中
    20. ui->Text1->setFont(QFont("华文行楷",16));//字体
    21. }
    22. APP::~APP()
    23. {
    24. delete ui;
    25. }
    26. void APP::on_SB1start_clicked()//Start按钮触发事件
    27. {
    28. //启动后时间文本编辑器、文本编辑器和启动按钮将不可用
    29. ui->SB1->setEnabled(false);
    30. ui->Line1->setEnabled(false);
    31. ui->Text1->setEnabled(false);
    32. timer_T2 = new QTimer(this);//定时器T2
    33. T1->start(100);
    34. connect(T1,&QTimer::timeout,this,&APP::time_slot2);
    35. }
    36. void APP::on_SB2stop_clicked()//Stop按钮触发事件
    37. {
    38. ui->SB1->setEnabled(true);
    39. ui->Line1->setEnabled(true);
    40. ui->Text1->setEnabled(true);
    41. }
    42. void APP::time_slot1()//获取SYS时间显示
    43. {
    44. QTime sys_time = QTime::currentTime();//获取系统时间
    45. QString t = sys_time.toString("hh:mm:ss");//时间转成字符串
    46. ui->Lb1->setText(t);//时间字符串t=>ui.lab中
    47. if(k1 == true)
    48. {
    49. ui->Line1->setText(ui->Lb1->text());
    50. k1 = false;
    51. }
    52. }
    53. void APP::time_slot2()//计时触发操作
    54. {
    55. if(ui->Line1->text() == ui->Lb1->text())
    56. {
    57. speecher->say(ui->Text1->toPlainText());//语音播放内容
    58. }
    59. }

    app.h

    1. #ifndef APP_H
    2. #define APP_H
    3. #include
    4. #include //时间类
    5. #include //定时器类
    6. #include
    7. #include
    8. QT_BEGIN_NAMESPACE
    9. namespace Ui { class APP; }
    10. QT_END_NAMESPACE
    11. class APP : public QWidget
    12. {
    13. Q_OBJECT
    14. public:
    15. APP(QWidget *parent = nullptr);
    16. ~APP();
    17. void time_slot1();
    18. void time_slot2();
    19. private slots:
    20. void on_SB1start_clicked();
    21. void on_SB2stop_clicked();
    22. private:
    23. Ui::APP *ui;
    24. QTimer *T1;
    25. QTimer *timer_T2;
    26. QTextToSpeech *speecher;
    27. };
    28. #endif // APP_H

    t2.pro

    1. QT += core gui texttospeech
    2. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    3. CONFIG += c++11
    4. # The following define makes your compiler emit warnings if you use
    5. # any Qt feature that has been marked deprecated (the exact warnings
    6. # depend on your compiler). Please consult the documentation of the
    7. # deprecated API in order to know how to port your code away from it.
    8. DEFINES += QT_DEPRECATED_WARNINGS
    9. # You can also make your code fail to compile if it uses deprecated APIs.
    10. # In order to do so, uncomment the following line.
    11. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    12. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    13. SOURCES += \
    14. main.cpp \
    15. app.cpp
    16. HEADERS += \
    17. app.h
    18. FORMS += \
    19. app.ui
    20. # Default rules for deployment.
    21. qnx: target.path = /tmp/$${TARGET}/bin
    22. else: unix:!android: target.path = /opt/$${TARGET}/bin
    23. !isEmpty(target.path): INSTALLS += target

  • 相关阅读:
    MAX4/11/03/016/08/1/1/00 MAX-4/11/01/008/08/1/1/00
    【李沐深度学习笔记】矩阵计算(4)
    kali渗透测试_HTTPS攻击
    rabbitMQ学习-死信队列
    进制转换计算器
    采用WPF开发第二版OFD阅读器,持续完善中,敬请期待!
    驱动上下游高效协同,跨境B2B电商平台如何释放LED产业供应链核心价值
    Win11如何更改默认下载路径?Win11更改默认下载路径的方法
    沉睡者IT - 为你解密那些卖虚拟资源和知识付费课程的平台到底有多简单和多赚钱。
    Mybatis-Plus的介绍和使用
  • 原文地址:https://blog.csdn.net/ainitjq1314/article/details/132655129