QT學習記錄7 檔案的讀取操作

2021-10-23 08:45:27 字數 1506 閱讀 3614

學到了關於qt–檔案讀取操作了

在qt可以進行檔案的讀寫、資訊讀取操作。

接下來嘗試:

執行出來的介面:

先貼一下**(帶注釋):

#include

"widget.h"

#include

"ui_widget.h"

#include

#include

#include

#include

#include

#include

#include

#include

widget::

widget

(qwidget *parent)

:qwidget

(parent),ui

(new ui::widget));

}widget::

~widget()

首先先在設定的路徑下建乙個txt文件,隨便打幾個字:

選擇檔案後,路徑會顯示在單行文字框裡,內容會顯示在大文字框裡。選擇txt格式的檔案,嘗試:

執行之後關閉。在桌面上開啟,可見新的內容已經被寫入:

輸出檔案的大小、型別、名稱、建立日期、最近修改日期等

;//檔案路徑

qdebug()

<<

"檔案大小"

<

size()

;//檔案大小

qdebug()

<<

"檔案型別"

<

suffix()

;//檔案型別

qdebug()

<<

"檔名稱"

<

filename()

;//檔名稱

qdebug()

<<

"建立日期"

<

created()

.tostring

("yyyy/mm/dd hh:mm:ss");

//建立日期

qdebug()

<<

"最近修改時間"

<

lastmodified()

.tostring

("yyyy/mm/dd hh:mm:ss");

//最近修改日期

Qt學習之路21 檔案操作

io操作的本質就是讀寫一段連續的儲存空間。qfile file qstring c users song8023 desktop test.txt 定義乙個檔案qfile類物件時需要指定路徑和名字,if file.open qiodevice writeonly qiodevice text 以只寫...

python學習記錄(三) 檔案操作

操作檔案必須進行的三個步驟 開啟檔案 對檔案進行操作 讀,寫 關閉檔案 python中開啟檔案使用的是open函式,需要傳入檔案開啟的模式,所有檔案開啟模式如下 檔案開啟模式描述r 以唯讀模式開啟檔案,並將檔案指標指向檔案頭 如果檔案不存在會報錯 w以只寫模式開啟檔案,並將檔案指標指向檔案頭 如果檔...

VC學習筆記7檔案操作

在mfc中用cfile類來進行檔案讀寫 cfile file 建立檔案類 file.open xx.txt cfile modecreate cfile modereadwrite 建立檔案以讀寫方式開啟 file.write lalala 6 寫檔案 file.colse 關閉 要讀的話 unsi...