day4 qtqtqtc++

news/2025/2/12 8:48:20/

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_OBJECTpublic: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.ppmy.cn/news/824893.html

相关文章

win7电脑关机出现蓝屏怎么办?解决win7电脑关机蓝屏的方法

解决win7电脑关机蓝屏的方法 右键“计算机”→“属性”→“高级系统设置”;(详见下图) 出现以下界面&#xff0c;点击最下方一个“设置”;(详见下图) 把“自动重新启动”前的钩去掉&#xff0c;然后点击“确认”即可大功告成。(详见下图) 最后&#xff0c;若还会你关机有时候可…

win7一关机电脑就蓝屏

win7系统是一款非常高效的智能系统&#xff01;强大的工作能力是win7系统最值得称赞的地方&#xff0c;但是最近一直有小伙伴反应自己遇到了一关机就蓝屏的问题&#xff0c;今天小编就为大家带来了win7每次关机都蓝屏的解决办法让我们一起来看看吧。 win7一关机就蓝屏的解决办法…

电脑蓝屏怎么办

电脑蓝屏的惨痛经历 前言&#xff1a;最近新买了一个电脑&#xff0c;本来想着开发用的&#xff0c;但是没办法&#xff0c;个人是个码农&#xff0c;又是游戏爱好者&#xff0c;所以给电脑安装了很多乱七八糟的环境。结果这一搞不要紧&#xff0c;电脑直接被我玩出事了&#…

w7电脑蓝屏怎么解决_电脑蓝屏,教您电脑蓝屏怎么办

相信对于经常使用电脑的朋友来说,在使用电脑的过程中一定都没少碰到蓝屏的状况吧,那冰凉的蓝面孔一定令大家感到十分的讨厌吧,那那么我们将应该首先了解导致蓝屏的原因,才能更好的解决蓝屏的的这个问题啦。 我们平时在使用电脑的过程当中经常都会遇到各种各样的问题啊,比如…

linux电脑开机蓝屏,Windows 7电脑开机蓝屏怎么办 电脑开机蓝屏解决方法linux操作系统 -电脑资料...

今天出现电脑开机蓝屏这个问题是安装了Windows 7系统之后&#xff0c;我使用的是联想机器&#xff0c;后来在官方找到了关于电脑开机蓝屏解决方法&#xff0c;下面我把此文章分享一下各位朋友可参考&#xff0c; 故障现象&#xff1a; 近日微软推送8月份的更新补丁&#xff0c;…

人工智能学术顶会——NeurIPS 2022 议题(网络安全方向)清单、摘要与总结

按语&#xff1a;随着大模型的崛起&#xff0c;将AI再次推向一个高峰&#xff0c;受到的关注也越来越大。在网络安全领域&#xff0c;除4大安全顶会外&#xff0c;一些涉及AI的安全话题&#xff0c;包括对AI的攻防研究&#xff0c;以及应用AI做安全的研究方向&#xff0c;也会发…

win7电脑蓝屏没有修复计算机,win7电脑蓝屏怎么办

最近有不少使用win7的朋友反映电脑出现蓝屏现象&#xff0c;不知道电脑蓝屏原因&#xff0c;也不知道win7电脑蓝屏怎么办。其实有些电脑蓝屏我们也可以尝试自己解决&#xff0c;下面小编就给大家分享一些win7电脑蓝屏解决方法。 方法一&#xff1a;系统自动修复 1、蓝屏后重新启…

远程计算机蓝屏,什么原因造成了蓝屏 电脑蓝屏错误代码介绍

电脑蓝屏是在上网的时候再常见到的现象了&#xff0c;造成电脑蓝屏的原因很多&#xff0c;所以微软在操作系统中设计了蓝屏代码&#xff0c;让大家电脑在出现蓝屏的时候能够及时的发现是什么原因造成了蓝屏。 一般蓝屏代码都位于屏幕提示文字的第一段或者倒数第三段&#xff0c…