码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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

     

  • 相关阅读:
    postman怎么进行参数化?
    Python中如何定义类、基类、函数和变量?
    Apache Hadoop 输入格式示例
    vue的常用指令
    10M25DAF484I7G 10M16DAF484I7G FPGA现场可编程门阵列
    利用Python提取将Excel/PDF文件数据
    接入网络技术
    力扣刷题-链表-翻转链表
    算法竞赛入门【码蹄集新手村600题】(MT1351-1400)
    极简示例揭示 SwiftUI 中 @ObservedObject 与 @StateObject 状态的关键区别
  • 原文地址:https://blog.csdn.net/qq_53195772/article/details/133954042
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号