Qt 作业 24/3/26

1、实现闹钟

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

相关推荐

  1. <span style='color:red;'>QT</span><span style='color:red;'>作业</span>1

    QT作业1

    2024-03-27 09:26:03      62 阅读
  2. <span style='color:red;'>QT</span><span style='color:red;'>作业</span>2

    QT作业2

    2024-03-27 09:26:03      58 阅读
  3. <span style='color:red;'>QT</span><span style='color:red;'>作业</span>4

    QT作业4

    2024-03-27 09:26:03      55 阅读
  4. <span style='color:red;'>QT</span><span style='color:red;'>作业</span>3

    QT作业3

    2024-03-27 09:26:03      53 阅读
  5. <span style='color:red;'>QT</span>3<span style='color:red;'>作业</span>

    QT3作业

    2024-03-27 09:26:03      45 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 09:26:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 09:26:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 09:26:03       82 阅读
  4. Python语言-面向对象

    2024-03-27 09:26:03       91 阅读

热门阅读

  1. STM32 RC522智能门锁

    2024-03-27 09:26:03       40 阅读
  2. ref 解包细节

    2024-03-27 09:26:03       40 阅读
  3. VUE3——Proxy API 与VUE2——defineProperty API区别

    2024-03-27 09:26:03       37 阅读
  4. ubuntu开启ssh服务

    2024-03-27 09:26:03       39 阅读
  5. leetcode66-Plus One

    2024-03-27 09:26:03       34 阅读
  6. Docker in Docker(DinD)浅析

    2024-03-27 09:26:03       38 阅读
  7. STM32 库函数 3*4矩阵键盘

    2024-03-27 09:26:03       38 阅读
  8. Hive安装配置

    2024-03-27 09:26:03       33 阅读
  9. php获取文件列表(所有子目录文件)

    2024-03-27 09:26:03       43 阅读
  10. Docker搭建Etcd集群

    2024-03-27 09:26:03       43 阅读
  11. Spring Boot设置io临时目录

    2024-03-27 09:26:03       35 阅读
  12. go实现链表

    2024-03-27 09:26:03       37 阅读
  13. 计算机网络——网络基础1

    2024-03-27 09:26:03       39 阅读
  14. vue3 之 Pinia

    2024-03-27 09:26:03       35 阅读
  15. 第三十三章 配置服务器访问 - SSL TLS 参数

    2024-03-27 09:26:03       36 阅读