📄 qfile.3qt
字号:
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()..SH "void QFile::flush ()\fC [virtual]\fR"Flushes the file buffer to the disk..PPclose() also flushes the file buffer..PPReimplemented from QIODevice..SH "int QFile::getch ()\fC [virtual]\fR"Reads a single byte/character from the file..PPReturns the byte/character read, or -1 if the end of the file has been reached..PPSee also putch() and ungetch()..PPReimplemented from QIODevice..SH "int QFile::handle () const"Returns the file handle of the file..PPThis is a small positive integer, suitable for use with C library functions such as fdopen() and fcntl(), as well as with QSocketNotifier..PPIf the file is not open or there is an error, handle() returns -1..PPSee also QSocketNotifier..SH "QString QFile::name () const"Returns the name set by setName()..PPSee also setName() and QFileInfo::fileName()..SH "bool QFile::open ( int m )\fC [virtual]\fR"Opens the file specified by the file name currently set, using the mode \fIm\fR. Returns TRUE if successful, otherwise FALSE..PP.PPThe mode parameter \fIm\fR must be a combination of the following flags:.TPIO_Raw specified raw (non-buffered) file access..TPIO_ReadOnly opens the file in read-only mode..TPIO_WriteOnly opens the file in write-only mode (and truncates)..TPIO_ReadWrite opens the file in read/write mode, equivalent to \fC(IO_ReadOnly | IO_WriteOnly)\fR..TPIO_Append opens the file in append mode. This mode is very useful when you want to write something to a log file. The file index is set to the end of the file. Note that the result is undefined if you position the file index manually using at() in append mode..TPIO_Truncate truncates the file..TPIO_Translate enables carriage returns and linefeed translation for text files under MS-DOS, Windows and OS/2..PPThe raw access mode is best when I/O is block-operated using 4kB block size or greater. Buffered access works better when reading small portions of data at a time..PP\fBImportant:\fR When working with buffered files, data may not be written to the file at once. Call flush() to make sure the data is really written..PP\fBWarning:\fR We have experienced problems with some C libraries when a buffered file is opened for both reading and writing. If a read operation takes place immediately after a write operation, the read buffer contains garbage data. Worse, the same garbage is written to the file. Calling flush() before readBlock() solved this problem..PPIf the file does not exist and IO_WriteOnly or IO_ReadWrite is specified, it is created..PPExample:.PP.nf.br QFile f1( "/tmp/data.bin" );.br QFile f2( "readme.txt" );.br f1.open( IO_Raw | IO_ReadWrite | IO_Append );.br f2.open( IO_ReadOnly | IO_Translate );.br.fi.PPSee also name(), close(), isOpen() and flush()..PPExamples:.)l action/application.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 "bool QFile::open ( int m, FILE * f )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPOpens a file in the mode \fIm\fR using an existing file handle \fIf\fR. Returns TRUE if successful, otherwise FALSE..PPExample:.PP.nf.br #include <stdio.h>.br.br void printError( const char* msg ).br {.br QFile f;.br f.open( IO_WriteOnly, stderr );.br f.writeBlock( msg, qstrlen(msg) ); // write to stderr.br f.close();.br }.br.fi.PPWhen a QFile is opened using this function, close() does not actually close the file, only flushes it..PP\fBWarning:\fR If \fIf\fR is \fCstdin\fR, \fCstdout\fR, \fCstderr\fR, you may not be able to seek. See QIODevice::isSequentialAccess() for more information..PPSee also close()..SH "bool QFile::open ( int m, int f )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPOpens a file in the mode \fIm\fR using an existing file descriptor \fIf\fR. Returns TRUE if successful, otherwise FALSE..PPWhen a QFile is opened using this function, close() does not actually close the file..PPThe QFile that is opened using this function, is automatically set to be in raw mode; this means that the file input/output functions are slow. If you run into performance issues, you should try to use one of the other open functions..PP\fBWarning:\fR If \fIf\fR is one of 0 (stdin), 1 (stdout) or 2 (stderr), you may not be able to seek. size() is set to \fCINT_MAX\fR (in limits.h)..PPSee also close()..SH "int QFile::putch ( int ch )\fC [virtual]\fR"Writes the character \fIch\fR to the file..PPReturns \fIch\fR, or -1 if some error occurred..PPSee also getch() and ungetch()..PPReimplemented from QIODevice..SH "QByteArray QIODevice::readAll ()\fC [virtual]\fR"This convenience function returns all of the remaining data in the device..SH "Q_LONG QFile::readBlock ( char * p, Q_ULONG len )\fC [virtual]\fR"Reads at most \fIlen\fR bytes from the file into \fIp\fR and returns the number of bytes actually read..PPReturns -1 if a serious error occurred..PP\fBWarning:\fR We have experienced problems with some C libraries when a buffered file is opened for both reading and writing. If a read operation takes place immediately after a write operation, the read buffer contains garbage data. Worse, the same garbage is written to the file. Calling flush() before readBlock() solved this problem..PPSee also writeBlock()..PPExample: qwerty/qwerty.cpp..PPReimplemented from QIODevice..SH "Q_LONG QFile::readLine ( char * p, Q_ULONG maxlen )\fC [virtual]\fR"Reads a line of text..PPReads bytes from the file into the char* \fIp\fR, until end-of-line or \fImaxlen\fR bytes have been read, whichever occurs first. Returns the number of bytes read, or -1 if there was an error. The terminating newline is not stripped..PPThis function is efficient only for buffered files. Avoid readLine() for files that have been opened with the IO_Raw flag..PPSee also readBlock() and QTextStream::readLine()..PPReimplemented from QIODevice..SH "Q_LONG QFile::readLine ( QString & s, Q_ULONG maxlen )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReads a line of text..PPReads bytes from the file into string \fIs\fR, until end-of-line or \fImaxlen\fR bytes have been read, whichever occurs first. Returns the number of bytes read, or -1 if there was an error.g. end of file. The terminating newline is not stripped..PPThis function is efficient only for buffered files. Avoid readLine() for files that have been opened with the IO_Raw flag..PPNote that the string is read as plain Latin1 bytes, not Unicode..PPSee also readBlock() and QTextStream::readLine()..SH "bool QFile::remove ()"Removes the file specified by the file name currently set. Returns TRUE if successful; otherwise returns FALSE..PPThe file is closed before it is removed..SH "bool QFile::remove ( const QString & fileName )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves the file \fIfileName\fR. Returns TRUE if successful, otherwise FALSE..SH "void QFile::setDecodingFunction ( DecoderFn f )\fC [static]\fR"Sets the function for decoding 8-bit file names to \fIf\fR. The default uses the locale-specific 8-bit encoding..PPSee also encodeName() and decodeName()..SH "void QFile::setEncodingFunction ( EncoderFn f )\fC [static]\fR"Sets the function for encoding Unicode file names to \fIf\fR. The default encodes in the locale-specific 8-bit encoding..PPSee also encodeName()..SH "void QFile::setName ( const QString & name )"Sets the name of the file to \fIname\fR. The name may have no path, a relative path or an absolute absolute directory path..PPDo not call this function if the file has already been opened..PPIf the file name has no path or a relative path, the path used will be whatever the application's current directory path is \fIat the time of the open()\fR call..PPExample:.PP.nf.br QFile f;.br QDir::setCurrent( "/tmp" );.br f.setName( "readme.txt" );.br QDir::setCurrent( "/home" );.br f.open( IO_ReadOnly ); // opens "/home/readme.txt" under Unix.br.fi.PPNote that the directory separator "/" works for all operating systems supported by Qt..PPSee also name(), QFileInfo and QDir..SH "Offset QFile::size () const\fC [virtual]\fR"Returns the file size..PPSee also at()..PPReimplemented from QIODevice..SH "int QFile::ungetch ( int ch )\fC [virtual]\fR"Puts the character \fIch\fR back into the file and decrements the index if it is not zero..PPThis function is normally called to "undo" a getch() operation..PPReturns \fIch\fR, or -1 if some error occurred..PPSee also getch() and putch()..PPReimplemented from QIODevice..SH "SEE ALSO".BR http://doc.trolltech.com/qfile.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qfile.3qt) and the Qtversion (3.0.0).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -