直接繼承自qobject, 是輸入/輸出裝置的抽象類。提供了公共實現和抽象介面用於讀寫塊資料。
q3socket,
q3socketdevice,
qabstractsocket,
qbuffer,
qfile,
qlocalsocket,
qnetworkreply,
qprocess是它的子類。
開啟檔案:
bool open(openmode flags) override;
bool open(file *f, openmode ioflags, filehandleflags handleflags=dontclosehandle);
bool open(int fd, openmode ioflags, filehandleflags handleflags=dontclosehandle);
讀檔案:
qint64 read(char *data, qint64 maxlen);
qbytearray read(qint64 maxlen);
qbytearray readall();
qint64 readline(char *data, qint64 maxlen);
qbytearray readline(qint64 maxlen = 0);
寫檔案:
qint64 write(const char *data, qint64 len);
qint64 write(const char *data);
inline qint64 write(const qbytearray &data);
讀檔案:
qstring readline(qint64 maxlen = 0);
bool readlineinto(qstring *line, qint64 maxlen = 0);
qstring readall();
qstring read(qint64 maxlen);
運算子過載讀寫操作:
qtextstream &operator>>(qchar &ch);
…若干qtextstream &operator<<(qchar ch);
…若干例:
qfile myfile(「test.txt」);
myfile.open(qiodevice::writeonly);
qtextstream textstream(&myfile);
textstream<<「this is 1st line.\r\n」;
textstream<<「this is 2nd line.\r\n」;
textstream<<「this is 3rd line.\r\n」;
textstream.flush();
myfile.close();
運算子過載讀寫操作:
qdatastream &operator>>(qint8 &i);
…若干qdatastream &operator<<(qint8 i);
…若干例:
qfile file(「test.dat」);
file.open(qiodevice::writeonly);
qdatastream ds(&file);
ds << 1 << 2 << 「123123」;
18 檔案操作
1.了解檔案操作 思考 什麼是檔案?思考 檔案操作包含什麼?答 開啟,關閉,讀,寫,複製 思考 檔案操作的作用是什麼?答 讀取內容,寫入內容,備份內容.總結 檔案操作的作用就是把一些內容 資料 儲存存放起來,可以讓程式下一次執行的時候直接使用,而不必重新製作乙份,省時省力。2.檔案的基本操作 開啟檔...
QT下應用程式開發
一 應用程式的編輯與編譯 從最簡單也是最著名的hello word來學習qt。首先建立helloword.cpp mkdir hello vi helloword.cpp include int main int argc,char argv cd hello 指定交叉編譯器路徑 export pa...
Python基礎(18)檔案操作
在計算機中,檔案是以 二進位制 的方式儲存在磁碟上的 文字檔案和二進位制檔案 1.文字檔案 2.二進位制檔案 在計算機中要操作檔案的套路非常固定,一共包含三個步驟 開啟檔案2.讀 寫檔案 讀 將檔案內容讀入記憶體 read 寫 將記憶體內容寫入檔案 write 關閉檔案 序號函式 方法 說明01 o...