summaryrefslogtreecommitdiff
path: root/qmake/tools/qfile.cpp
Side-by-side diff
Diffstat (limited to 'qmake/tools/qfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qfile.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/qmake/tools/qfile.cpp b/qmake/tools/qfile.cpp
index a578b49..c088b55 100644
--- a/qmake/tools/qfile.cpp
+++ b/qmake/tools/qfile.cpp
@@ -67,49 +67,49 @@ extern bool qt_file_access( const QString& fn, int t );
The 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().
The 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().
The 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().
Here is a code fragment that uses QTextStream to read a text file
line by line. It prints each line with a line number.
\code
QStringList lines;
QFile file( "file.txt" );
if ( file.open( IO_ReadOnly ) ) {
QTextStream stream( &file );
QString line;
int i = 1;
- while ( !stream.eof() ) {
+ while ( !stream.atEnd() ) {
line = stream.readLine(); // line of text excluding '\n'
printf( "%3d: %s\n", i++, line.latin1() );
lines += line;
}
file.close();
}
\endcode
Writing text is just as easy. The following example shows how to
write the data we read into the string list from the previous
example:
\code
QFile file( "file.txt" );
if ( file.open( IO_WriteOnly ) ) {
QTextStream stream( &file );
for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it )
stream << *it << "\n";
file.close();
}
\endcode
The QFileInfo class holds detailed information about a file, such
as access permissions, file dates and file types.
@@ -269,48 +269,49 @@ bool QFile::remove()
# define OPEN_ASYNC O_NONBLOCK
#elif defined(O_NDELAY)
# define HAS_ASYNC_FILEMODE
# define OPEN_ASYNC O_NDELAY
#endif
/*!
Flushes the file buffer to the disk.
close() also flushes the file buffer.
*/
void QFile::flush()
{
if ( isOpen() && fh ) // can only flush open/buffered
fflush( fh ); // file
}
/*! \reimp
\fn QIODevice::Offset QFile::at() const
*/
/*!
Returns TRUE if the end of file has been reached; otherwise returns FALSE.
+ If QFile has not been open()'d, then the behavior is undefined.
\sa size()
*/
bool QFile::atEnd() const
{
if ( !isOpen() ) {
#if defined(QT_CHECK_STATE)
qWarning( "QFile::atEnd: File is not open" );
#endif
return FALSE;
}
if ( isDirectAccess() && !isTranslated() ) {
if ( at() < length )
return FALSE;
}
return QIODevice::atEnd();
}
/*!
Reads a line of text.
Reads bytes from the file into the char* \a p, until end-of-line
or \a maxlen bytes have been read, whichever occurs first. Returns