qt 文件管理系统 笔记1 目标 查看文件 类型 大小 路径 文件名 创建日期

项目结构

pro 文件

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    cell_main.cpp

HEADERS += \
    cell_main.h

FORMS += \
    cell_main.ui

DESTDIR = $$PWD/bin

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

头文件

#ifndef CELL_MAIN_H
#define CELL_MAIN_H

#include <QMainWindow>
#include <QStandardItemModel>

QT_BEGIN_NAMESPACE
namespace Ui { class Cell_Main; }
QT_END_NAMESPACE

class Cell_Main : public QMainWindow
{
    Q_OBJECT

public:
    Cell_Main(QWidget *parent = nullptr);
    ~Cell_Main();

    void updateFile();

private:
    Ui::Cell_Main *ui;

    QString m_strDataPath;
    QStandardItemModel m_model;
};
#endif // CELL_MAIN_H

cell_main.cpp 文件
#include "cell_main.h"
#include "ui_cell_main.h"
#include <QDir>
#include <QtDebug>
#include <QDateTime>

Cell_Main::Cell_Main(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Cell_Main)
{
    ui->setupUi(this);
    //获取当前应用所在目录  auto修饰变量
    m_strDataPath= QApplication::applicationDirPath()+"/data";

    QDir d(m_strDataPath);

    if(!d.exists())
    {
        d.mkdir(m_strDataPath);//数据保存
    }
    updateFile();

}

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

void Cell_Main::updateFile()
{
    QDir d(m_strDataPath);
    QStringList lFiter;
    lFiter <<"*.txt"<<"*.md";
    QFileInfoList lFilesInfo = d.entryInfoList(lFiter,QDir::Files);

    m_model.clear();

    QList<QStandardItem*> lRow;
    for(int i=0;i<lFilesInfo.size();i++)
    {
        lRow.clear();
        QFileInfo &info=lFilesInfo[i];
        //序号
        QStandardItem *p1 = new QStandardItem(info.completeSuffix());
        QStandardItem *p2 = new QStandardItem(info.absoluteFilePath());
        QStandardItem *p3 = new QStandardItem(info.baseName());
        QStandardItem *p4 = new QStandardItem(info.birthTime().toString("yyy/mm/dd hh:mm:ss"));
        QStandardItem *p5 = new QStandardItem(info.lastModified().toString("yyy/mm/dd hh:mm:ss"));
        QStandardItem *p6 = new QStandardItem(QString::number(info.size()/1024)+"KB");
        lRow<<p1<<p2<<p3<<p4<<p5<<p6;
        m_model.appendRow(lRow);

    }
    QStringList lHeaders{"文件类型","绝对路径","文件名","创建日期","最后一次修改","文件大小"};
    ui->tableView->setModel(&m_model);
}

ui

 http://t.csdnimg.cn/TQbfe

CSDN

 CSDN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值