day4 qtqtqtc++

news2024/10/6 2:32:11

cppcpp

 

 

 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>640</width>
    <height>480</height>
   </rect>
  </property>
  <property name="minimumSize">
   <size>
    <width>640</width>
    <height>480</height>
   </size>
  </property>
  <property name="maximumSize">
   <size>
    <width>640</width>
    <height>480</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>闹钟 - by zzy</string>
  </property>
  <property name="styleSheet">
   <string notr="true"/>
  </property>
  <widget class="QLabel" name="label">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>20</y>
     <width>300</width>
     <height>120</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>浪漫雅圆</family>
     <pointsize>36</pointsize>
    </font>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(85, 170, 255);</string>
   </property>
   <property name="text">
    <string>TextLabel</string>
   </property>
  </widget>
  <widget class="QPushButton" name="start_btn">
   <property name="geometry">
    <rect>
     <x>370</x>
     <y>90</y>
     <width>100</width>
     <height>50</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>浪漫雅圆</family>
     <pointsize>12</pointsize>
    </font>
   </property>
   <property name="styleSheet">
    <string notr="true"/>
   </property>
   <property name="text">
    <string>启动</string>
   </property>
  </widget>
  <widget class="QPushButton" name="stop_btn">
   <property name="geometry">
    <rect>
     <x>510</x>
     <y>90</y>
     <width>100</width>
     <height>50</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>浪漫雅圆</family>
     <pointsize>12</pointsize>
    </font>
   </property>
   <property name="styleSheet">
    <string notr="true"/>
   </property>
   <property name="text">
    <string>关闭</string>
   </property>
  </widget>
  <widget class="QTextEdit" name="textEdit">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>160</y>
     <width>600</width>
     <height>300</height>
    </rect>
   </property>
  </widget>
  <widget class="QTimeEdit" name="timeEdit">
   <property name="geometry">
    <rect>
     <x>370</x>
     <y>20</y>
     <width>240</width>
     <height>60</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>浪漫雅圆</family>
     <pointsize>12</pointsize>
    </font>
   </property>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimer>              //定时器类的头文件
#include <QTime>               //时间类的头文件
#include <QTimerEvent>         //定时器事件处理类
#include <QDateTime>           //日期时间类
#include <QMessageBox>         //消息提醒框类
#include <QTextToSpeech>       //文本转语音

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_start_btn_clicked();
    void on_stop_btn_clicked();
    void timeout_slot();

private:
    Ui::Widget *ui;

    QTimer *t1;     //定义一个定时器指针
    bool flag=0;    //判断闹钟是否启动
    QTextToSpeech *speecher;       //定义播报者指针
};

#endif // WIDGET_H

 

 

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

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setFixedSize(640,480);
    this->setWindowTitle("闹钟 - by zzy");

    //给定时器指针实例化空间
    t1 = new QTimer(this);  //显示当前时间

    //将t1的timeout信号绑定到自定义的槽函数中
    connect(t1, &QTimer::timeout, this, &Widget::timeout_slot);
    t1->start(200);

    //实例化播报者对象
    speecher = new QTextToSpeech(this);

    //设置关闭按钮不可用
    ui->stop_btn->setEnabled(false);

    //设置label显示格式
    ui->label->setAlignment(Qt::AlignCenter);

}

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

//启动按钮的槽函数
void Widget::on_start_btn_clicked()
{
    //设置按钮/文本框是否可用
    ui->start_btn->setEnabled(false);
    ui->stop_btn->setEnabled(true);
    ui->timeEdit->setEnabled(false);
    ui->textEdit->setEnabled(false);
    flag = 1;

}

//关闭按钮的槽函数
void Widget::on_stop_btn_clicked()
{
    //设置按钮/文本框是否可用
    ui->start_btn->setEnabled(true);
    ui->stop_btn->setEnabled(false);
    ui->timeEdit->setEnabled(true);
    ui->textEdit->setEnabled(true);
    flag = 0;
}

//定时器时间结束的槽函数
void Widget::timeout_slot()
{
    //获取系统当前时间
    QTime sys_time = QTime::currentTime();
    //将QTime转换成字符串
    QString time = sys_time.toString("hh:mm:ss");
    QString time2 = ui->timeEdit->time().toString("hh:mm:ss");
    //将时间显示在label上
    ui->label->setText(time);

    if(flag==1 && time == time2)
    {
        speecher->say(ui->textEdit->toPlainText());
        QMessageBox::information(this, "闹钟", ui->textEdit->toPlainText());
        ui->start_btn->setEnabled(true);
        ui->stop_btn->setEnabled(false);
        ui->timeEdit->setEnabled(true);
        ui->textEdit->setEnabled(true);
        flag = 0;
    }
}

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

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

相关文章

Linux--获取与杀死当前进程PID

获取当前进程的代码&#xff1a; #include <sys/types.h>pid_t idgetpid();//获取的是自己的进程PID 杀死当前进程的指令&#xff1a; kill -9 进程的PID 我要是kill -9 16865(-bash进程)&#xff0c;你会发现无论你输入clear、ls、还是vim...指令&#xff0c;都无…

云深处绝影四足机器人协议学习解析

绝影四足机器人通信协议学习解析 本学习文档介绍了云深处 绝影X20 四足机器人的通信协议&#xff0c;并对相关的通信机制和命令格式进行了简单的解析。该协议在机器人系统和上位机&#xff08;例如外部板卡或系统&#xff09;之间进行TCP通信时使用。 1. 协议端口号 在此协议…

定义一个派生自D1的D2类,并且在D2中覆盖pvf();建立一个D2类的对象并且调用f()、vf()、pvf()

运行代码&#xff1a; //定义一个派生自D1的D2类&#xff0c;并且在D2中覆盖pvf() //建立一个D2类的对象并且调用f()、vf()、pvf() #include"std_lib_facilities.h" //---------------------------------------------------------------------- //定义B1类。 class …

配置通过域名访问网站(NETBASE第七课)

1 DNS服务器 域名系统_百度百科 域名和与之相对应的IP地址转换的服务器 DNS&#xff08;Domain Name Server&#xff0c;域名服务器&#xff09;是进行域名(domain name)和与之相对应的IP地址 (IP address)转换的服务器。DNS中保存了一张域名(domain name)和与之相对应的IP地…

通过GitHub Desktop,将本地项目上传到gitee上

介绍 这里主要介绍&#xff0c;通过 gitHub Desktop 软件&#xff0c;将本地的项目&#xff0c;上传到 gitee的仓库里&#xff08;这里仓库为新建的仓库&#xff0c;什么东西都没有&#xff09;。 这里主要介绍&#xff0c;仓库的新建方式&#xff0c;及本地代码上传到远端的操…

Unity 实现一个揭面膜效果

源码 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

【Django】列表页面的搜索功能

目的 页面列表增加多字段搜索显示查询结果 方案 分页显示搜索结果 效果 实现 列表页面 # list.html <div class"pull-left" style"margin-bottom: 10px"><form action"{% url api-search %}" method"get"><div …

ModaHub魔搭社区:开源向量数据库的Milvus怎么读?

Milvus是一个中文词语,意为“Milvus navigate,为智慧找方向,为价值做链接,为创作者做伙伴”。在读这个词语时,可以按照以下方式发音: 首先,我们需要将Milvus这个词语分解成多个音节。根据汉语拼音的规则,可以将其分解为“mi”、“lu”、“su”。 接下来,我们需要根…

Java阶段五Day03

Java阶段五Day03 文章目录 Java阶段五Day03回顾git命令Git远程仓库远程仓库概念远程仓库分支操作分支管理策略 回顾git命令 本地版本控制 git initgit addgit commitgit loggit statusgit taggit refloggit reset 分支管理 git branchgit branch b1git checkout b1git merg…

C#核心知识回顾——13.多线程、预处理器指令

1.多线程 了解线程前先了解进程 进程&#xff08;Process&#xff09;是计算机中的程序关于某数据集合上的一次运行活动 是系统进行资源分配和调度的基本单位&#xff0c;是操作系统结构的基础 说人话&#xff1a;打开个应用程序就是在慢作系统上开启了一个进程 进程之间可以相…

【Vscode】解决 An SSH installation couldn‘t be found

【Vscode】解决 An SSH installation couldn‘t be found 背景描述&#xff1a;在vscode中使用ssh进行连接到时候&#xff0c;已经安装了ssh romote的plugin插件&#xff0c;但是在输入了ssh连接命令之后&#xff0c;仍然出现报错&#xff1a;an ssh installation could not be…

vue3+mapboxgl鼠标浮动显示cgcs2000

一、需求 鼠标在地图中浮动展示地图的经纬度&#xff0c;cgcs2000 xy 还有显示带号 二、实现效果 展示经度&#xff0c;纬度&#xff0c;x值&#xff0c;y值显示的是带号和y值 三、思路 3.1、mapbox获取经纬度方法 初始化地图后.on方法中有个mousemove方法 mapboxUtil._m…

leetcode:递增的三元子序列

递增的三元子序列 题解部分转自leetcode:Xzz medium 给你一个整数数组 nums &#xff0c;判断这个数组中是否存在长度为 3 的递增子序列。 如果存在这样的三元组下标 (i, j, k) 且满足 i < j < k &#xff0c;使得 nums[i] < nums[j] < nums[k] &#xff0c;返回…

专享策略06 | 盘口策略CTP实盘版

量化策略开发&#xff0c;高质量社群&#xff0c;交易思路分享等相关内容 『正文』 ˇ 大家好&#xff0c;我们在6月29日发布了盘口策略| 回测版&#xff0c;今天我们做好了CTP的实盘版本供俱乐部会员使用和玩耍&#xff0c;今天主要说明一下如何使用CTP实盘版本。 先回顾一…

线上展厅设计方案,个性化自主打造720漫游展厅

导语&#xff1a; 随着科技的不断进步&#xff0c;线上展厅作为一种新型的展示方式&#xff0c;在现代社会得到了广泛的应用。线上展厅通过虚拟技术和创新设计&#xff0c;突破了时间和地域的限制&#xff0c;为企业和观众带来了全新的展览体验。本文将重点探讨线上展厅的优势和…

【工具使用】STM32CubeMX-单ADC模式规则通道配置

一、概述 无论是新手还是大佬&#xff0c;基于STM32单片机的开发&#xff0c;使用STM32CubeMX都是可以极大提升开发效率的&#xff0c;并且其界面化的开发&#xff0c;也大大降低了新手对STM32单片机的开发门槛。     本文主要讲述STM32芯片的ADC的配置及其相关知识。 二、…

6. Springboot快速回顾(集成Dubbo)

Dubbo是实现远程调用的一个框架&#xff0c;阿里巴巴开源的。远程调用就是B服务器可以调用A服务器的方法。大型项目会被拆分成多个模块&#xff0c;部署在不同的服务器上。若将公共模块集中部署在一台服务器上&#xff0c;可以方便其他服务器调用。因此&#xff0c;需要Dubbo。…

java代码实现自动录入数据

之前工作中遇到粘贴复制大量数据&#xff0c;研究一下java代码解放双手 模拟鼠标录入数据 引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.3.0.RELEASE&…

本地私有化部署大模型RWKV-懒人包一键安装享受专属免费大模型-RWKV Runner

仓库地址&#xff1a;https://github.com/josStorer/RWKV-Runner 预设配置已经开启自定义CUDA算子加速&#xff0c;速度更快&#xff0c;且显存消耗更少。如果你遇到可能的兼容性问题&#xff0c;前往配置页面&#xff0c;关闭使用自定义CUDA算子加速 如果Windows Defender说这…

Flutter:架构概览

概览 Flutter本质上是一个跨平台的UI工具集&#xff0c;允许在各自操作系统上复用同样的代码。 尽可能提供原生体验的高性能和复用代码。 开发中&#xff0c;Flutter应用在一个VM上运行&#xff0c;使得可在保留状态且无需重新编译情况下&#xff0c;进行热加载。 发行时&…