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

相关推荐
爱喝水的鱼丶几秒前
SAP-ABAP:高效开发指南:全局唯一标识符ICF_CREATE_GUID函数的全面解析与实践
运维·服务器·开发语言·数据库·sap·abap·开发交流
徐同保1 分钟前
python使用vscode打断点调试
开发语言·python
toooooop86 分钟前
php BC MATH扩展函数巧妙进行财务金额四舍五入
开发语言·php
运维行者_10 分钟前
用Applications Manager监控HAProxy:保障负载均衡高效稳定
运维·开发语言·前端·数据库·tcp/ip·负载均衡·服务器监控
wy31362282110 分钟前
C#——报错:System.Net.Sockets.SocketException (10049): 在其上下文中,该请求的地址无效。
开发语言·c#·.net
遨游xyz12 分钟前
策略模式笔记
开发语言·word·bash
睡美人的小仙女1278 小时前
Threejs加载环境贴图报错Bad File Format: bad initial token
开发语言·javascript·redis
rayufo9 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk9 小时前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
缺点内向9 小时前
C#编程实战:如何为Word文档添加背景色或背景图片
开发语言·c#·自动化·word·.net