Qt 作业 24/3/26

1、实现闹钟

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTime>
#include <QLineEdit>

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 *event);

private slots:
    void on_pushButton_clicked();

private:
    Ui::Widget *ui;
    int id;//定时器id
};
#endif // WIDGET_H
cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    id = startTimer(1000);
}

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

void Widget::timerEvent(QTimerEvent *event)
{
    //获取系统时间
    QTime sys_time = QTime::currentTime();
    //转换为字符串
    QString s = sys_time.toString("hh:mm:ss");
    //将时间设置到ui界面的lab中
    ui->sys_time->setText(s);
    //比较时间
    if(ui->sys_time->text() == ui->clock_lab->text())
    {
        ui->show_lab->setText("R U OK???");
    }
    //居中
    ui->sys_time->setAlignment(Qt::AlignCenter);
}

void Widget::on_pushButton_clicked()
{
    QString s= ui->lineEdit->text();
    ui->clock_lab->setText(s);
}

2、思维导图

相关推荐
一抓掉一大把14 分钟前
秒杀-StackExchangeRedisHelper连接单例
java·开发语言·jvm
星释28 分钟前
Rust 练习册 :Minesweeper与二维数组处理
开发语言·后端·rust
虾米Life41 分钟前
基于微服务脚手架的视频点播系统 (仿B站) [客户端] -1
c++·qt·微服务·架构
开发者小天1 小时前
React中的useRef的用法
开发语言·前端·javascript·react.js
xixixin_1 小时前
【React】检测元素是否出现在用户视窗内
开发语言·前端·javascript·react.js
Js_cold2 小时前
Verilog局部参数localparam
开发语言·fpga开发·verilog
Acrelhuang2 小时前
小小电能表,如何撬动家庭能源革命?
java·大数据·开发语言·人工智能·物联网
头发还没掉光光2 小时前
Linux网络初始及网络通信基本原理
linux·运维·开发语言·网络·c++
疏狂难除2 小时前
spiderdemo第22题与webassembly的跨域
开发语言·javascript·爬虫·rust·wasm·mitmproxy
WenGyyyL2 小时前
微信小程序开发——第二章:微信小程序开发环境搭建
开发语言·python·微信小程序