QTday3消息弹框/计时器

编程入门 行业动态 更新时间:2024-10-17 05:33:17

QTday3消息弹框/<a href=https://www.elefans.com/category/jswz/34/1762036.html style=计时器"/>

QTday3消息弹框/计时器

闹钟小软件

 widget.cpp

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QDebug>
#include <QPushButton>
#include <QLabel>
#include <QTimer>
#include <QTimerEvent>
#include <QTime>
#include <QMessageBox>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void timerEvent(QTimerEvent *e);//重写定时器事件函数private:Ui::Widget *ui;
public:int timeId;bool isSettingAlarmClock = false;
private slots:void on_startBtn_clicked();void on_stopBtn_clicked();
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);ui->stopBtn->setEnabled(false);ui->startBtn->setEnabled(true);ui->clockLineEdit->setEnabled(true);ui->textEdit->setEnabled(false);ui->textEdit->clear();isSettingAlarmClock = false;//开启定时器timeId = startTimer(1000);
}void Widget::timerEvent(QTimerEvent *e){//如果定时器不是 timeId, 直接返回if(e->timerId() != timeId){return;}//刷新展示当前时间QTime sys_time = QTime::currentTime();QString time = sys_time.toString("hh:mm:ss");ui->currentTimeBtn->setText(time);//如果 设置闹钟标识为false 直接返回if(true !=isSettingAlarmClock){return;}//设置闹钟标识为true 判断是否到设置的闹钟时间, 是->播报声音或提示, 虚拟机播放不了声音,就只提示if(time == ui->clockLineEdit->text()){int ret = QMessageBox::information(this,"提示","闹钟时间到啦,赶紧起来电脑开机学习!!!",QMessageBox::Yes,QMessageBox::Yes);if(ret == QMessageBox::Yes){qDebug()<<"好的,我赶紧起来开电脑";}qDebug()<<"闹钟时间到了";}
}Widget::~Widget()
{killTimer(timeId);delete ui;
}void Widget::on_startBtn_clicked()
{if(ui->clockLineEdit->text().isEmpty() || ui->clockLineEdit->text().isNull()){int ret = QMessageBox::information(this,"提示","还没设置闹钟时间,来设置时间:比如:12:00:00",QMessageBox::Yes,QMessageBox::Yes);if(ret == QMessageBox::Yes){qDebug()<<"好的,我赶紧起来开电脑";}return;}ui->startBtn->setEnabled(false);ui->stopBtn->setEnabled(true);ui->clockLineEdit->setEnabled(false);ui->textEdit->setEnabled(false);ui->textEdit->setText("三更灯火五更鸡\n正式男儿读书时\n黑发不知勤学早\n白发方悔读书迟");this->isSettingAlarmClock = true;
}void Widget::on_stopBtn_clicked()
{ui->stopBtn->setEnabled(false);ui->startBtn->setEnabled(true);ui->clockLineEdit->setEnabled(true);ui->textEdit->clear();ui->textEdit->setEnabled(false);ui->clockLineEdit->clear();isSettingAlarmClock = false;
}/*程序启动: 停止按钮不可点击/开始按钮可点击/闹钟提示置空/闹钟edit置空/闹钟标识置为false1开启定时器tId_currentTime, 记时事件处理显示当前时间2点击开始按钮: 停止按钮可点击/开始按钮不可点击/闹钟提示文本设置/闹钟edit不可点击/闹钟标识置为true. 比较当前时间 == 编辑时间, 相同播报文字 否则不播报,3点击停止: 闹钟标识置为false 停止按钮不可点击/开始按钮可点击/闹钟提示置空/闹钟edit置空. 定时器不比较时间 只展示时间
*/

markdown笔记:思维导图不利于复习知识点和查找搜索, 所以写的markdown

 

更多推荐

QTday3消息弹框/计时器

本文发布于:2024-02-27 15:22:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1707098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计时器   消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!