7.27 作业 QT

news2024/9/22 19:31:58

要求:

 结果图:

clock.pro:

QT       += core gui
QT += texttospeech

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

FORMS += \
    widget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

 widget.h:

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimerEvent>  //定时器事件处理函数
#include <QTime>    //时间类
#include <QPushButton>  //按钮类头文件
#include <QTextToSpeech>   //文本转语音类头文件

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 *e);    //要重写的关于定时器事件处理函数的声明

private slots:
    void on_start_Btn_clicked();

    void on_stop_Btn_clicked();

private:
    Ui::Widget *ui;

    static int count;   //定义静态变量

    QTextToSpeech *speecher;  //定义一个播报者

    //定义一个基于事件处理的定时器id
    int tid1;
    int tid2;
};
#endif // WIDGET_H

widget.cpp:

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    tid1 = startTimer(1000);    //启动一个定时器,隔1s会自动执行timerevent函数

    //设置占位符
    ui->clock_lineEdit->setPlaceholderText("输入多少秒后开启闹铃");

    speecher = new QTextToSpeech(this);
}

int Widget::count = 0;

Widget::~Widget()
{
    delete ui;
}

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() == tid1)
    {
             //获取系统事件
          QTime sys_time = QTime::currentTime();  //QTime类对象

            //将时间转化为字符串
          QString t = sys_time.toString("hh:mm:ss");

         //将字符串展示到ui界面
          ui->time_lab->setText(t);
          ui->time_lab->setAlignment(Qt::AlignHCenter);

    }else if(event->timerId() == tid2)
    {
        count++;

        //将clock_lineEdit 的文本转化为整数
        int m = ui->clock_lineEdit->text().toInt();

        if(count == m)
        {
            //进行语音播报
            speecher->say(ui->read_textEdit->toPlainText());

            //停止计时器
            killTimer(tid2);
        }
    }

}

void Widget::on_start_Btn_clicked()
{

    //将start_Btn设置成不可用状态
    ui->start_Btn->setEnabled(false);

    //将clock_lineEdit设置成不可用状态
    ui->clock_lineEdit->setEnabled(false);

    //将stop_Btn设置成可用状态
    ui->stop_Btn->setEnabled(true);

    //启动第二个计时器
    tid2 = startTimer(1000);    //启动一个定时器,隔1s会自动执行timerevent函数

    //将count置零
    count = 0;

}

void Widget::on_stop_Btn_clicked()
{
    //停止语音播报
    speecher->stop();

    //将stop_Btn设置成不可用状态
    ui->stop_Btn->setEnabled(false);

    //将start_Btn设置成可用状态
    ui->start_Btn->setEnabled(true);
    ui->clock_lineEdit->setEnabled(true);

    //停止计时器
    killTimer(tid2);

    //将count置零
    count = 0;
}

widget.ui:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Widget</class>
 <widget class="QWidget" name="Widget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>613</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Widget</string>
  </property>
  <widget class="QLabel" name="time_lab">
   <property name="geometry">
    <rect>
     <x>50</x>
     <y>60</y>
     <width>321</width>
     <height>161</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <pointsize>22</pointsize>
     <weight>75</weight>
     <italic>false</italic>
     <bold>true</bold>
     <underline>true</underline>
    </font>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(85, 255, 255);</string>
   </property>
   <property name="text">
    <string/>
   </property>
  </widget>
  <widget class="QLineEdit" name="clock_lineEdit">
   <property name="geometry">
    <rect>
     <x>430</x>
     <y>60</y>
     <width>291</width>
     <height>71</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(255, 255, 0);</string>
   </property>
  </widget>
  <widget class="QPushButton" name="start_Btn">
   <property name="geometry">
    <rect>
     <x>430</x>
     <y>160</y>
     <width>121</width>
     <height>61</height>
    </rect>
   </property>
   <property name="text">
    <string>开始</string>
   </property>
  </widget>
  <widget class="QPushButton" name="stop_Btn">
   <property name="geometry">
    <rect>
     <x>590</x>
     <y>160</y>
     <width>121</width>
     <height>61</height>
    </rect>
   </property>
   <property name="text">
    <string>停止</string>
   </property>
  </widget>
  <widget class="QTextEdit" name="read_textEdit">
   <property name="geometry">
    <rect>
     <x>50</x>
     <y>250</y>
     <width>671</width>
     <height>341</height>
    </rect>
   </property>
   <property name="html">
    <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:18pt; color:#55ffff;&quot;&gt;故人西辞黄鹤楼,唱跳Rap打篮球。春风又绿江南岸,练习长达两年半。清明时节雨坤坤,路上行人梳中分,借问背带何处有,牧童遥指我爱坤。长江后浪推前浪,爱坤啥样我啥样。鸡冠头背带裤,我是爱坤你记住。向阳花木易为春,听说你爱蔡徐坤。小黑子树枝666,蒸虾头,好丸吗?树枝赶人,蒸五鱼,食不食油饼,我家鸽鸽在胎上拿姜拿到手软,他那么努力,这样叫我怎么荔枝?已经橘爆你了,再这样我就抱紧了,劝你苏珊,不然我们爱坤就紫砂了。&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

思维导图:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/799162.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

No Spring环境Mybatis-Plus批量插入并返回主键的两种方式

批量插入,可以把Mybatis-Plus看作是Mybatis加强版;故Mybatis中的相关操作都可以在Mybatis-Plus中使用;在mysql数据库中支持批量插入&#xff0c;所以只要配置useGeneratedKeys和keyProperty就可以批量插入并返回主键了。 下面是批量插入的Dao层接口 一注解方式: 直接撸代码:…

面向对象编程:深入理解Java接口

文章目录 1. 接口&#xff1a;定义与生活中的类比2. 如何定义一个接口3. 接口中的成员4. 接口的实现4.1 单个接口的实现4.2 多个接口的实现 5. 多态与接口6. 新特性&#xff1a;默认方法与私有方法 接口在Java开发中扮演着重要的角色&#xff0c;它为类之间的交互定义了标准和规…

JDBC的的使用

首先导入jar包。 https://downloads.mysql.com/archives/c-j/ package com.test.sql;import java.sql.*;public class StudySql {public static void init() throws SQLException {Statement stmt null;Connection conn null;ResultSet res null;PreparedStatement pstm…

双点双向重发布实验

第一步配置IP地址 R1: [R1]int Serial 4/0/0 [R1-Serial4/0/0]ip address 12.0.0.1 24 [R1-Serial4/0/0]int g 0/0/0 [R1-GigabitEthernet0/0/0]ip address 14.0.0.1 24 [R1-GigabitEthernet0/0/0]int l0 [R1-LoopBack0]ip address 1.1.1.1 24 R2,R3,R4配置相同 第二步&#x…

一招教你用Java多线程写出死锁!!!

首先我们要知道什么是死锁&#xff1a; 1&#xff09;进程死锁是指两个或两个以上的进程在执行过程中&#xff0c;由于竞争资源或者由于彼此通信而造成的一种阻塞的现象&#xff0c;若无外力作用&#xff0c;它们都将无法推进下去。此时称系统处于死锁状态或系统产生了死锁&am…

今天学学消息队列RocketMQ:消息类型

RocketMQ支持的消息类型有三种&#xff1a;普通消息、顺序消息、延时消息、事务消息。以下内容的代码部分都是基于rocketmq-spring-boot-starter做的。 普通消息 普通消息是一种无序消息&#xff0c;消息分布在各个MessageQueue当中&#xff0c;以保证效率为第一使命。这种消息…

一、Spring源码-ApplicationContext

Spring源码篇-ApplicationContext 一、ApplicationContext ApplicationContext到底是什么&#xff1f;字面含义是应用的上下文。这块我们需要看看ApplicationContext的具体的结构。 通过ApplicationContext实现的相关接口来分析&#xff0c;ApplicationContext接口在具备BeanF…

【正规方程对波士顿房价数据集进行预测】

数据准备 我们首先需要加载波士顿房价数据集。该数据集包含房屋特征信息和对应的房价标签。 import pandas as pd import numpy as npdata_url "http://lib.stat.cmu.edu/datasets/boston" raw_df pd.read_csv(data_url, sep"\s", skiprows22, headerN…

初代AIGC明星独角兽,停摆在大模型元年

唏嘘&#xff01;AIGC方兴未艾&#xff0c;但国内AIGC领域的昔日龙头独角兽&#xff0c;正站在风雨飘摇的悬崖边。 影谱科技&#xff0c;初代目AIGC明星公司&#xff0c;被爆已经面临经营不善、运营停摆的窘境。 这家成立于2009年的AI影像公司&#xff0c;一直专注大文娱产业…

JAVA线上问题排查降龙十八掌

现场问题一般有以下几种问题 CPU,磁盘&#xff0c;内存&#xff0c;GC问题&#xff0c;网络 同时例如jstack、jmap等工具也是不囿于一个方面的问题的&#xff0c;基本上出问题就是df、free、top 三连&#xff0c;然后依次jstack、jmap伺候&#xff0c;具体问题具体分析即可。 …

Vue3解决:Mockjs 引入后并访问 404(Not Found) 的页面报错问题

1、问题描述&#xff1a; 其一、报错为&#xff1a; GET http://localhost:5173/list 404 (Not Found) ncaught (in promise) AxiosError {message: Request failed with status code 404, name: AxiosError, code: ERR_BAD_REQUEST, config: {…}, request: XMLHttpRequest,…

【C语言初阶】指针篇—上

目录 1. 指针是什么&#xff1f;2. 指针和指针类型2.1 指针-整数2.2 指针的解引用 3. 野指针3.1 野指针成因1. 指针未初始化2. 指针越界访问3. 指针指向的空间释放 3.2 如何规避野指针 1. 指针是什么&#xff1f; 指针是什么&#xff1f; 指针理解的2个要点&#xff1a; > 1…

DAY14_FilterListenerAjaxAxiosJsonfastjson综合案例-axios和html交互

目录 1 Filter1.1 Filter概述1.2 Filter快速入门1.2.1 开发步骤1.2.2 代码演示 1.3 Filter执行流程1.4 Filter拦截路径配置1.5 过滤器链1.5.1 概述1.5.2 代码演示1.5.3 问题 1.6 案例1.6.1 需求1.6.2 分析1.6.3 代码实现1.6.3.1 创建Filter1.6.3.2 编写逻辑代码1.6.3.3 测试并抛…

计算机组成原理问答7

外围设备 1. I/O设备 输入设备(鼠标、键盘)、输出设备(显示器、打印机)、外存设备(光盘、硬盘) 2. I/O接口 又称I/O控制器、设备控制器,负责协调主机与外部设备之间的数据传输。 I/O控制方式 3. 程序查询方式 中断 关中断作用:实现原子操作。屏蔽可屏蔽的中断。…

备战秋招 | 笔试强训16

目录 一、选择题 二、编程题 三、选择题题解 四、编程题题解 一、选择题 1、下列一段 C 代码的输出结果是&#xff08;&#xff09; #include <iostream> class Base { public:int Bar(char x){return (int)(x);}virtual int Bar(int x){return (2 * x);} }; clas…

如何启用路由器dhcp?快解析如何内网穿透?

一、什么是DHCP&#xff1f; 动态主机设置协议&#xff08;DHCP&#xff09;是一种使网络管理员能够集中管理和自动分配 IP 网络地址的通信协议。在网络中&#xff0c;每个联网设备都需要分配独有的 IP 地址。并当有新计算机移到网络中的其它位置时&#xff0c;能自动收到新的…

【阅读笔记】一种暗通道优先的快速自动白平衡算法

解决问题: 自动白平衡算法中存在白色区域检测错误导致白平衡失效的问题,作者提出了一种基于暗通道优先的白平衡算法。 算法思想: 图像中白色区域或者高饱和度区域的光线透射率较低,根据以上特性利用暗通道法计算图像中白色区域。 算法概述: 作者使用何凯明提出的基于暗…

MLP-Mixer:面向视觉的全mlp架构

文章目录 MLP-Mixer: An all-MLP Architecture for Vision摘要本文方法代码实验结果 MLP-Mixer: An all-MLP Architecture for Vision 摘要 卷积神经网络(cnn)是计算机视觉的首选模型。 最近&#xff0c;基于注意力的网络&#xff0c;如VIT&#xff0c;也变得流行起来。在本文…

四种刷题模式的爱刷题无后端无数据库刷题应用网站H5源码

四种刷题模式的爱刷题无后端无数据库刷题应用网站H5源码。提供了简单轻量化的部署方式和详细的四种刷题模式教程。该应用使用JSON作为题库的存储方式&#xff0c;层次清晰、结构简单易懂。 配套的word模板和模板到JSON转换工具可供使用&#xff0c;方便将题库从word格式转换为…

Python显示循环代码的进度条

目录 1. tqdm库 2. alive_progress库 3. progressbar库 1. tqdm库 tqdm是一个快速&#xff0c;可扩展的Python进度条&#xff0c;可以在Python长循环中添加一个进度提示信息 import time from tqdm import trangefor i in trange(100):# do somethingtime.sleep(0.5) 2. a…