Qt獲取檔案屬性

2021-06-28 08:45:15 字數 988 閱讀 8706

在qt中有qfileinfo類專門提供了獲取檔案資訊的各種介面,比如檔名稱,位置資訊,檔案的許可權,目錄,檔案或符號連線,檔案大小,建立時間,最後修改時等等,下面通過**來看一些具體的屬性獲取。

#ifndef mainwindow_h

#define mainwindow_h

#include qt_begin_namespace

namespace ui

qt_end_namespace

class mainwindow : public qmainwindow

;#endif // mainwindow_h

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include #include #include #include #include #include mainwindow::mainwindow(qwidget *parent)

: qmainwindow(parent)

, ui(new ui::mainwindow)

mainwindow::~mainwindow()

void mainwindow::initview()

void mainwindow::slotopenfile()

else

qstring infolist;

qfile file(filepath);

if(file.open(qiodevice::readonly | qiodevice::text))

else

}

#include "mainwindow.h"

執行結果 :

參考

獲取檔案屬性函式

表頭檔案 include 函式定義 int stat const char file name,struct stat buf 函式說明 通過檔名filename獲取檔案資訊,並儲存在buf所指的結構體stat中 返回值 執行成功則返回0,失敗返回 1,錯誤 存於errno 需要include er...

常用檔案屬性獲取

朱老師物聯網大講堂 學習筆記 檔案屬性,檔案的屬性資訊,只能被專用的api開啟看到,常用的api有,stat,fstat,lstat,同時stat也是乙個shell命令,其內部呼叫的也是stat,int stat const char path,struct stat buf int fstat i...

獲取檔案屬性 stat lstat fstat

一 函式原型 include include include int stat const char path,struct stat buf int fstat int fd,struct stat buf int lstat const char path,struct stat buf 二 引...