⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfile.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QFile 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQFile \- I/O device that operates on files.PP\fC#include <qfile.h>\fR.PPInherits QIODevice..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQFile\fR ()".br.ti -1c.BI "\fBQFile\fR ( const QString & name )".br.ti -1c.BI "\fB~QFile\fR ()".br.ti -1c.BI "QString \fBname\fR () const".br.ti -1c.BI "void \fBsetName\fR ( const QString & name )".br.ti -1c.BI "typedef QCString (* \fBEncoderFn\fR ) ( const QString & fileName )".br.ti -1c.BI "typedef QString (* \fBDecoderFn\fR ) ( const QCString & localfileName )".br.ti -1c.BI "bool \fBexists\fR () const".br.ti -1c.BI "bool \fBremove\fR ()".br.ti -1c.BI "virtual bool \fBopen\fR ( int m )".br.ti -1c.BI "bool \fBopen\fR ( int m, FILE * f )".br.ti -1c.BI "bool \fBopen\fR ( int m, int f )".br.ti -1c.BI "virtual void \fBclose\fR ()".br.ti -1c.BI "virtual void \fBflush\fR ()".br.ti -1c.BI "virtual Offset \fBsize\fR () const".br.ti -1c.BI "virtual Offset \fBat\fR () const".br.ti -1c.BI "virtual bool \fBat\fR ( Offset pos )".br.ti -1c.BI "virtual bool \fBatEnd\fR () const".br.ti -1c.BI "virtual Q_LONG \fBreadBlock\fR ( char * p, Q_ULONG len )".br.ti -1c.BI "virtual Q_LONG \fBreadLine\fR ( char * p, Q_ULONG maxlen )".br.ti -1c.BI "Q_LONG \fBreadLine\fR ( QString & s, Q_ULONG maxlen )".br.ti -1c.BI "virtual int \fBgetch\fR ()".br.ti -1c.BI "virtual int \fBputch\fR ( int ch )".br.ti -1c.BI "virtual int \fBungetch\fR ( int ch )".br.ti -1c.BI "int \fBhandle\fR () const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "QCString \fBencodeName\fR ( const QString & fileName )".br.ti -1c.BI "QString \fBdecodeName\fR ( const QCString & localFileName )".br.ti -1c.BI "void \fBsetEncodingFunction\fR ( EncoderFn f )".br.ti -1c.BI "void \fBsetDecodingFunction\fR ( DecoderFn f )".br.ti -1c.BI "bool \fBexists\fR ( const QString & fileName )".br.ti -1c.BI "bool \fBremove\fR ( const QString & fileName )".br.in -1c.SS "Important Inherited Members".in +1c.ti -1c.BI "virtual QByteArray \fBreadAll\fR ()".br.in -1c.SH DESCRIPTIONThe QFile class is an I/O device that operates on files..PPQFile is an I/O device for reading and writing binary and text files. A QFile may be used by itself or more conveniently with a QDataStream or QTextStream..PPThe file name is usually passed in the constructor but can be changed with setName(). You can check for a file's existence with exists() and remove a file with remove()..PPThe file is opened with open(), closed with close() and flushed with flush(). Data is usually read and written using QDataStream or QTextStream, but you can read with readBlock() and readLine() and write with writeBlock(). QFile also supports getch(), ungetch() and putch()..PPThe size of the file is returned by size(). You can get the current file position or move to a new file position using the at() functions. If you've reached the end of the file, atEnd() returns TRUE. The file handle is returned by handle()..PPHere is a code fragment that uses QTextStream to read a text file line by line. It prints each line with a line number..PP.nf.br    QFile f("file.txt");.br    if ( f.open(IO_ReadOnly) ) {    // file opened successfully.br        QTextStream t( &f );        // use a text stream.br        QString s;.br        int n = 1;.br        while ( !t.eof() ) {        // until end of file....br            s = t.readLine();       // line of text excluding '\\n'.br            printf( "%3d: %s\\n", n++, s.latin1() );.br        }.br        f.close();.br    }.br.fi.PPThe QFileInfo class holds detailed information about a file, such as access permissions, file dates and file types..PPThe QDir class manages directories and lists of file names..PPQt uses Unicode file names. If you want to do your own I/O on Unix systems you may want to use encodeName() (and decodeName()) to convert the file name into the local encoding..PPSee also QDataStream, QTextStream and Input/Output and Networking..SS "Member Type Documentation".SH "QFile::DecoderFn"This is used by QFile::setDecodingFunction()..SH "QFile::EncoderFn"This is used by QFile::setEncodingFunction()..SH MEMBER FUNCTION DOCUMENTATION.SH "QFile::QFile ()"Constructs a QFile with no name..SH "QFile::QFile ( const QString & name )"Constructs a QFile with a file name \fIname\fR..PPSee also setName()..SH "QFile::~QFile ()"Destroys a QFile. Calls close()..SH "bool QFile::at ( Offset pos )\fC [virtual]\fR"Sets the file index to \fIpos\fR. Returns TRUE if successful; otherwise returns FALSE..PPExample:.PP.nf.br    QFile f( "data.bin" );.br    f.open( IO_ReadOnly );                      // index set to 0.br    f.at( 100 );                                // set index to 100.br    f.at( f.at()+50 );                          // set index to 150.br    f.at( f.size()-80 );                        // set index to 80 before EOF.br    f.close();.br.fi.PPUse at() without arguments to retrieve the file offset..PP\fBWarning:\fR The result is undefined if the file was open()'ed using the IO_Append specifier..PPSee also size() and open()..PPReimplemented from QIODevice..SH "Offset QFile::at () const\fC [virtual]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the position in the file..PPSee also size()..PPReimplemented from QIODevice..SH "bool QFile::atEnd () const\fC [virtual]\fR"Returns TRUE if the end of file has been reached; otherwise returns FALSE..PPSee also size()..PPReimplemented from QIODevice..SH "void QFile::close ()\fC [virtual]\fR"Closes an open file..PPThe file is not closed if it was opened with an existing file handle. If the existing file handle is a \fCFILE*\fR, the file is flushed. If the existing file handle is an \fCint\fR file descriptor, nothing is done to the file..PPSome "write-behind" filesystems may report an unspecified error on closing the file. These errors only indicate that something may have gone wrong since the previous open(). In such a case status() reports IO_UnspecifiedError after close(), otherwise IO_Ok..PPSee also open() and flush()..PPExamples:.)l addressbook/centralwidget.cpp, application/application.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp, qdir/qdir.cpp, qwerty/qwerty.cpp and xml/outliner/outlinetree.cpp..PPReimplemented from QIODevice..SH "QString QFile::decodeName ( const QCString & localFileName )\fC [static]\fR"This does the reverse of QFile::encodeName() using \fIlocalFileName\fR..PPSee also setDecodingFunction()..SH "QCString QFile::encodeName ( const QString & fileName )\fC [static]\fR"When you use QFile, QFileInfo, and QDir to access the file system with Qt, you can use Unicode file names. On Unix, these file names are converted to an 8-bit encoding. If you want to do your own file I/O on Unix, you should convert the file name using this function. On Windows NT, Unicode file names are supported directly in the file system and this function should be avoided. On Windows 95, non-Latin1 locales are not supported at this time..PPBy default, this function converts \fIfileName\fR to the local 8-bit encoding determined by the user's locale. This is sufficient for file names that the user chooses. File names hard-coded into the application should only use 7-bit ASCII filename characters..PPThe conversion scheme can be changed using setEncodingFunction(). This might be useful if you wish to give the user an option to store file names in utf-8, etc., but be ware that such file names would probably then be unrecognizable when seen by other programs..PPSee also decodeName()..SH "bool QFile::exists ( const QString & fileName )\fC [static]\fR"Returns TRUE if the file given by \fIfileName\fR exists; otherwise returns FALSE..PPExamples:.)l dirview/dirview.cpp and helpviewer/helpwindow.cpp..SH "bool QFile::exists () const"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -