QTextStream(3qt) QTextStream(3qt)
NAME
QTextStream - Basic functions for reading and writing text using a QIODevice
SYNOPSIS
All the functions in this class are reentrant when Qt is built with thread support.</p>
#include <qtextstream.h>
Inherited by QTextIStream and QTextOStream.
Public Members
enum Encoding { Locale, Latin1, Unicode, UnicodeNetworkOrder, UnicodeReverse, RawUnicode, UnicodeUTF8 }
void setEncoding ( Encoding e )
void setCodec ( QTextCodec * codec )
QTextCodec * codec ()
QTextStream ()
QTextStream ( QIODevice * iod )
QTextStream ( QString * str, int filemode )
QTextStream ( QString & str, int filemode ) (obsolete)
QTextStream ( QByteArray a, int mode )
QTextStream ( FILE * fh, int mode )
virtual ~QTextStream ()
QIODevice * device () const
void setDevice ( QIODevice * iod )
void unsetDevice ()
bool atEnd () const
bool eof () const (obsolete)
QTextStream & operator>> ( QChar & c )
QTextStream & operator>> ( char & c )
QTextStream & operator>> ( signed short & i )
QTextStream & operator>> ( unsigned short & i )
QTextStream & operator>> ( signed int & i )
QTextStream & operator>> ( unsigned int & i )
QTextStream & operator>> ( signed long & i )
QTextStream & operator>> ( unsigned long & i )
QTextStream & operator>> ( float & f )
QTextStream & operator>> ( double & f )
QTextStream & operator>> ( char * s )
QTextStream & operator>> ( QString & str )
QTextStream & operator>> ( QCString & str )
QTextStream & operator<< ( QChar c )
QTextStream & operator<< ( char c )
QTextStream & operator<< ( signed short i )
QTextStream & operator<< ( unsigned short i )
QTextStream & operator<< ( signed int i )
QTextStream & operator<< ( unsigned int i )
QTextStream & operator<< ( signed long i )
QTextStream & operator<< ( unsigned long i )
QTextStream & operator<< ( float f )
QTextStream & operator<< ( double f )
QTextStream & operator<< ( const char * s )
QTextStream & operator<< ( const QString & s )
QTextStream & operator<< ( const QCString & s )
QTextStream & operator<< ( void * ptr )
QTextStream & readRawBytes ( char * s, uint len )
QTextStream & writeRawBytes ( const char * s, uint len )
QString readLine ()
QString read ()
void skipWhiteSpace ()
int flags () const
int flags ( int f )
int setf ( int bits )
int setf ( int bits, int mask )
int unsetf ( int bits )
void reset ()
int width () const
int width ( int w )
int fill () const
int fill ( int f )
int precision () const
int precision ( int p )
DESCRIPTION
The QTextStream class provides basic functions for reading and writing text using a QIODevice.
The text stream class has a functional interface that is very similar to that of the standard C++ iostream class.
Qt provides several global functions similar to the ones in iostream: <center>.nf
</center>
Warning: By default QTextStream will automatically detect whether integers in the stream are in decimal, octal, hexadecimal or binary
format when reading from the stream. In particular, a leading '0' signifies octal, i.e. the sequence "0100" will be interpreted as 64.
The QTextStream class reads and writes text; it is not appropriate for dealing with binary data (but QDataStream is).
By default, output of Unicode text (i.e. QString) is done using the local 8-bit encoding. This can be changed using the setEncoding()
method. For input, the QTextStream will auto-detect standard Unicode "byte order marked" text files; otherwise the local 8-bit encoding is
used.
The QIODevice is set in the constructor, or later using setDevice(). If the end of the input is reached atEnd() returns TRUE. Data can be
read into variables of the appropriate type using the operator>>() overloads, or read in its entirety into a single string using read(), or
read a line at a time using readLine(). Whitespace can be skipped over using skipWhiteSpace(). You can set flags for the stream using
flags() or setf(). The stream also supports width(), precision() and fill(); use reset() to reset the defaults.
See also QDataStream, Input/Output and Networking, and Text Related Classes.
Member Type Documentation
QTextStream::Encoding
QTextStream::Locale
QTextStream::Latin1
QTextStream::Unicode
QTextStream::UnicodeNetworkOrder
QTextStream::UnicodeReverse
QTextStream::RawUnicode
QTextStream::UnicodeUTF8
See setEncoding() for an explanation of the encodings.
MEMBER FUNCTION DOCUMENTATION
QTextStream::QTextStream ()
Constructs a data stream that has no IO device.
QTextStream::QTextStream ( QIODevice * iod )
Constructs a text stream that uses the IO device iod.
QTextStream::QTextStream ( QString * str, int filemode )
Constructs a text stream that operates on the Unicode QString, str, through an internal device. The filemode argument is passed to the
device's open() function; see QIODevice::mode().
If you set an encoding or codec with setEncoding() or setCodec(), this setting is ignored for text streams that operate on QString.
Example:
QString str;
QTextStream ts( &str, IO_WriteOnly );
ts << "pi = " << 3.14; // str == "pi = 3.14"
Writing data to the text stream will modify the contents of the string. The string will be expanded when data is written beyond the end of
the string. Note that the string will not be truncated:
QString str = "pi = 3.14";
QTextStream ts( &str, IO_WriteOnly );
ts << "2+2 = " << 2+2; // str == "2+2 = 414"
Note that because QString is Unicode, you should not use readRawBytes() or writeRawBytes() on such a stream.
QTextStream::QTextStream ( QString & str, int filemode )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
This constructor is equivalent to the constructor taking a QString* parameter.
QTextStream::QTextStream ( QByteArray a, int mode )
Constructs a text stream that operates on the byte array, a, through an internal QBuffer device. The mode argument is passed to the
device's open() function; see QIODevice::mode().
Example:
QByteArray array;
QTextStream ts( array, IO_WriteOnly );
ts << "pi = " << 3.14 << '