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

相关推荐
Felix_One2 天前
Qt 串口通信避坑指南:QSerialPort 的 5 个常见问题
qt
blasit5 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
郑州光合科技余经理10 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo12310 天前
matlab画图工具
开发语言·matlab
dustcell.10 天前
haproxy七层代理
java·开发语言·前端
norlan_jame10 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone10 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ40220549610 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月10 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
m0_5312371710 天前
C语言-数组练习进阶
c语言·开发语言·算法