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、思维导图

相关推荐
XR12345678844 分钟前
办公网自主创新建设怎么选?信创办公场景的选型逻辑
开发语言·php
郝学胜-神的一滴1 小时前
Effective Python 条款4:字符串格式化大乱斗
开发语言·网络·python·程序人生·软件工程
Ramble_Naylor1 小时前
只借不占:Rust 的引用与借用
开发语言·rust
FreeTinker1 小时前
Java文件服务器的技术选型与实现路径:从嵌入式工具到企业级系统
java·服务器·开发语言
2501_906565121 小时前
小创 · 智能助手
开发语言·c#
benchmark_cc2 小时前
1000只ETF的5分钟K线如何批量获取?QuantDash分页策略与高性能Python实践
开发语言·人工智能·爬虫·python·算法·quantdash·量化数据源
Coodor2 小时前
如何在web浏览器使用js操作CPU卡
开发语言·前端·javascript·cpu卡
我星期八休息2 小时前
Linux I/O多路转接—epoll
java·linux·运维·服务器·开发语言·jvm·算法
大模型码小白2 小时前
AI 提示词专栏:使用系统指令(System Prompt)实现全局约束
java·大数据·运维·开发语言·人工智能·python·prompt