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

📄 qfile.3qt

📁 Trolltech公司发布的基于C++图形开发环境
💻 3QT
📖 第 1 页 / 共 2 页
字号:
.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..PPThe mode parameter \fIm\fR must be a combination of the following flags:.TP\fCIO_Raw\fR specified raw (non-buffered) file access..TP\fCIO_ReadOnly\fR opens the file in read-only mode..TP\fCIO_WriteOnly\fR opens the file in write-only mode (and truncates)..TP\fCIO_ReadWrite\fR opens the file in read/write mode, equivalent to \fC(IO_ReadOnly|IO_WriteOnly).\fR.TP\fCIO_Append\fR 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..TP\fCIO_Truncate\fR truncates the file..TP\fCIO_Translate\fR 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 \fCIO_WriteOnly\fR or \fCIO_ReadWrite\fR 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 );.fi.PPSee also name(), close(), isOpen() and flush()..PPReimplemented from QIODevice..SH "bool QFile::open ( int m, FILE * f )"Opens 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    }.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, stdout, stderr,\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 )"Opens 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..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 "int QFile::readBlock ( char * p, uint 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()..PPReimplemented from QIODevice..SH "int QFile::readLine ( QString & s, uint maxlen )"Reads a line of text..PPReads bytes from the file until end-of-line is reached, or up to \fImaxlen\fR bytes, and returns the number of bytes read, or -1 in case of 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 \fCIO_Raw\fR flag..PPNote that the string is read as plain Latin1 bytes, not Unicode..PPSee also readBlock() and QTextStream::readLine()..SH "int QFile::readLine ( char * p, uint maxlen ) \fC[virtual]\fR"Reads a line of text..PPReads bytes from the file until end-of-line is reached, or up to \fImaxlen\fR bytes, and returns the number of bytes read, or -1 in case of 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 \fCIO_Raw\fR flag..PPSee also readBlock() and QTextStream::readLine()..PPReimplemented from QIODevice..SH "bool QFile::remove ()"Removes the file specified by the file name currently set. Returns TRUE if successful, otherwise FALSE..PPThe file is closed before it is removed..SH "bool QFile::remove ( const QString & fileName ) \fC[static]\fR"Removes 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 filenames. 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 filenames. 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. The name can include an absolute directory path or it can be a name or a path relative to the current directory..PPDo not call this function if the file has already been opened..PPNote that if the name is relative QFile does not associate it with the current directory. If you change directory before calling open(), open uses the new current directory..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.fi.PPAlso note that the directory separator '/' works for all operating systems supported by Qt..PPSee also name(), QFileInfo and QDir..SH "uint 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 "int QFile::writeBlock ( const QByteArray & data )"Reimplemented for internal reasons; the API is not affected..SH "int QFile::writeBlock ( const char * p, uint len ) \fC[virtual]\fR"Reimplemented for internal reasons; the API is not affected..PPWrites \fIlen\fR bytes from \fIp\fR to the file and returns the number of bytes actually written..PPReturns -1 if a serious error occurred..PP\fBWarning:\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..PPSee also readBlock()..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 make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qfile.3qt) and the Qtversion (2.3.10).

⌨️ 快捷键说明

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