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

📄 qfile.3qt

📁 Linux下的基于X11的图形开发环境。
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QFile 3qt "9 December 2002" "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.SH SYNOPSISAlmost all the functions in this class are reentrant when Qt is built with thread support. The exceptions are \fBsetEncodingFunction\fR() and \fBsetDecodingFunction\fR().</p>.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 bool \fBatEnd\fR () const".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    QStringList lines;.br    QFile file( "file.txt" );.br    if ( file.open( IO_ReadOnly ) ) {.br        QTextStream stream( &file );.br        QString line;.br        int i = 1;.br        while ( !stream.eof() ) {.br            line = stream.readLine(); // line of text excluding '\\n'.br            printf( "%3d: %s\\n", i++, line.latin1() );.br            lines += line;.br        }.br        file.close();.br    }.br.fi.PPWriting text is just as easy. The following example shows how to write the data we read into the string list from the previous example:.PP.nf.br    QFile file( "file.txt" );.br    if ( file.open( IO_WriteOnly ) ) {.br        QTextStream stream( &file );.br        for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ).br            stream << *it << "\\n";.br        file.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::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 application/application.cpp, chart/chartform_files.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/2000, 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..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 aware 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 chart/chartform.cpp, dirview/dirview.cpp, and helpviewer/helpwindow.cpp..SH "bool QFile::exists () const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns TRUE if this file exists; otherwise returns FALSE..PPSee also name().

⌨️ 快捷键说明

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