• C++&QT---QT-day3


    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. //需要在.pro文件第一行加 texttospeech
    4. Widget::Widget(QWidget *parent)
    5. : QWidget(parent)
    6. , ui(new Ui::Widget)
    7. {
    8. ui->setupUi(this);
    9. ui->lineEdit->setPlaceholderText("时:分:秒");//设定框占位字符
    10. //ui->textEdit->setText("春眠不觉晓");
    11. ui->lineEdit->setAlignment(Qt::AlignCenter);//居中显示
    12. ui->textEdit->setAlignment(Qt::AlignCenter);
    13. speecher=new QTextToSpeech(this);//给播报员分配空间
    14. }
    15. Widget::~Widget()
    16. {
    17. delete ui;
    18. }
    19. void Widget:: timerEvent(QTimerEvent *e)
    20. {
    21. if(e->timerId() == tId)
    22. {
    23. QTime sys_time = QTime::currentTime(); //获取当前系统时间
    24. QString s = sys_time.toString("hh:mm:ss");//把系统时间转换成字符串
    25. ui->lab_time->setText(s);//将系统时间放入标签中
    26. ui->lab_time->setAlignment(Qt::AlignCenter);//居中显示
    27. if(s == ui->lineEdit->text())//判断设定时间与系统时间是否匹配
    28. {
    29. speecher->say(ui->textEdit->toPlainText());
    30. }
    31. }
    32. }
    33. void Widget::on_startBtn_clicked()//定时器启动事件
    34. {
    35. tId=startTimer(1000);
    36. }
    37. void Widget::on_stopBtn_clicked()//定时器关闭事件
    38. {
    39. this->killTimer(tId);
    40. }

     

    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. QT_BEGIN_NAMESPACE
    11. namespace Ui { class Widget; }
    12. QT_END_NAMESPACE
    13. class Widget : public QWidget
    14. {
    15. Q_OBJECT
    16. public:
    17. Widget(QWidget *parent = nullptr);
    18. ~Widget();
    19. void timerEvent(QTimerEvent *e);
    20. private slots:
    21. void on_startBtn_clicked();
    22. void on_stopBtn_clicked();
    23. private:
    24. Ui::Widget *ui;
    25. int tId;
    26. QTextToSpeech *speecher;
    27. };
    28. #endif // WIDGET_H

     

  • 相关阅读:
    基于STM32设计的药品柜温湿度监测系统(华为云IOT)(184)
    Sentinel实战
    MongoDB数据迁移之迁移工具Kettle
    SpringCloud——网关Gateway
    HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Stack
    Python---while循环的执行流程 解释
    mybatis generator 表名多了个点
    数据结构-单链表
    Day1讲题题单
    yii2,脚本内存溢出解决办法
  • 原文地址:https://blog.csdn.net/qq_53195772/article/details/133954042