QTextStream Class Reference

The QTextStream class provides a convenient interface for reading and writing text.

  1. #include <QTextStream>

Inherited by: QTextIStream and QTextOStream.

Note: All functions in this class are reentrant.

Detailed Description

The QTextStream class provides a convenient interface for reading and writing text.

QTextStream can operate on a QIODevice, a QByteArray or a QString. Using QTextStream's streaming operators, you can conveniently read and write words, lines and numbers. For generating text, QTextStream supports formatting options for field padding and alignment, and formatting of numbers. Example:

  1.                 QFile data("output.txt");
  2. if (data.open(QFile::WriteOnly | QFile::Truncate))  {
  3.     QTextStream out(&data);
  4.     out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7;
  5.     // writes "Result: 3.14      2.7       "
  6. }

It's also common to use QTextStream to read console input and write console output. QTextStream is locale aware, and will automatically decode standard input using the correct codec. Example:

  1. QTextStream stream(stdin);
  2. QString line;
  3. do  {
  4.     line = stream.readLine();
  5. } while (!line.isNull());

Note that you cannot use QTextStream::atEnd(), which returns true when you have reached the end of the data stream, with stdin. The reason for this is that as long as stdin doesn't give any input to the QTextStream, atEnd() will return true even if the stdin is open and waiting for more characters.

Besides using QTextStream's constructors, you can also set the device or string QTextStream operates on by calling setDevice() or setString(). You can seek to a position by calling seek(), and atEnd() will return true when there is no data left to be read. If you call flush(), QTextStream will empty all data from its write buffer into the device and call flush() on the device.

Internally, QTextStream uses a Unicode based buffer, and QTextCodec is used by QTextStream to automatically support different character sets. By default, QTextCodec::codecForLocale() is used for reading and writing, but you can also set the codec by calling setCodec(). Automatic Unicode detection is also supported. When this feature is enabled (the default behavior), QTextStream will detect the UTF-16 or the UTF-32 BOM (Byte Order Mark) and switch to the appropriate UTF codec when reading. QTextStream does not write a BOM by default, but you can enable this by calling setGenerateByteOrderMark(true). When QTextStream operates on a QString directly, the codec is disabled.

There are three general ways to use QTextStream when reading text files:

  • Chunk by chunk, by calling readLine() or readAll().
  • Word by word. QTextStream supports streaming into QStrings, QByteArrays and char* buffers. Words are delimited by space, and leading white space is automatically skipped.
  • Character by character, by streaming into QChar or char types. This method is often used for convenient input handling when parsing files, independent of character encoding and end-of-line semantics. To skip white space, call skipWhiteSpace().

Since the text stream uses a buffer, you should not read from the stream using the implementation of a superclass. For instance, if you have a QFile and read from it directly using QFile::readLine() instead of using the stream, the text stream's internal position will be out of sync with the file's position.

By default, when reading numbers from a stream of text, QTextStream will automatically detect the number's base representation. For example, if the number starts with "0x", it is assumed to be in hexadecimal form. If it starts with the digits 1-9, it is assumed to be in decimal form, and so on. You can set the integer base, thereby disabling the automatic detection, by calling setIntegerBase(). Example:

  1. QTextStream in("0x50 0x20");
  2. int firstNumber, secondNumber;
  3.  
  4. in >> firstNumber;             // firstNumber == 80
  5. in >> dec >> secondNumber;     // secondNumber == 0
  6.  
  7. char ch;
  8. in >> ch;                      // ch == 'x'

QTextStream supports many formatting options for generating text. You can set the field width and pad character by calling setFieldWidth() and setPadChar(). Use setFieldAlignment() to set the alignment within each field. For real numbers, call setRealNumberNotation() and setRealNumberPrecision() to set the notation (SmartNotation, ScientificNotation, FixedNotation) and precision in digits of the generated number. Some extra number formatting options are also available through setNumberFlags().

Like <iostream> in the standard C++ library, QTextStream also defines several global manipulator functions:

ManipulatorDescription
binSame as setIntegerBase(2).
octSame as setIntegerBase(8).
decSame as setIntegerBase(10).
hexSame as setIntegerBase(16).
showbaseSame as setNumberFlags(numberFlags() | ShowBase).
forcesignSame as setNumberFlags(numberFlags() | ForceSign).
forcepointSame as setNumberFlags(numberFlags() | ForcePoint).
noshowbaseSame as setNumberFlags(numberFlags() & ~ShowBase).
noforcesignSame as setNumberFlags(numberFlags() & ~ForceSign).
noforcepointSame as setNumberFlags(numberFlags() & ~ForcePoint).
uppercasebaseSame as setNumberFlags(numberFlags() | UppercaseBase).
uppercasedigitsSame as setNumberFlags(numberFlags() | UppercaseDigits).
lowercasebaseSame as setNumberFlags(numberFlags() & ~UppercaseBase).
lowercasedigitsSame as setNumberFlags(numberFlags() & ~UppercaseDigits).
fixedSame as setRealNumberNotation(FixedNotation).
scientificSame as setRealNumberNotation(ScientificNotation).
leftSame as setFieldAlignment(AlignLeft).
rightSame as setFieldAlignment(AlignRight).
centerSame as setFieldAlignment(AlignCenter).
endlSame as operator<<('\n') and flush().
flushSame as flush().
resetSame as reset().
wsSame as skipWhiteSpace().
bomSame as setGenerateByteOrderMark(true).

In addition, Qt provides three global manipulators that take a parameter: qSetFieldWidth(), qSetPadChar(), and qSetRealNumberPrecision().

See also QDataStream, QIODevice, QFile, QBuffer, QTcpSocket, and Codecs Example.

Public Types

Toggle detailsenum QTextStream::

FieldAlignmentFieldAlignment { AlignLeft , AlignRight , AlignCenter , AlignAccountingStyle 3 ...} { AlignLeft , AlignRight , AlignCenter , AlignAccountingStyle 3 }

This enum specifies how to align text in fields when the field is wider than the text that occupies it.

ConstantValueDescription
QTextStream::AlignLeft 0 Pad on the right side of fields.
QTextStream::AlignRight 1 Pad on the left side of fields.
QTextStream::AlignCenter 2 Pad on both sides of field.
QTextStream::AlignAccountingStyle 3 Same as AlignRight, except that the sign of a number is flush left.

See also setFieldAlignment().

Look up this member in the source code.

Toggle detailsenum QTextStream::

NumberFlagNumberFlag { ShowBase , ForcePoint , ForceSign , UppercaseBase , UppercaseDigits 0x10 ...} { ShowBase , ForcePoint , ForceSign , UppercaseBase , UppercaseDigits 0x10 }

This enum specifies various flags that can be set to affect the output of integers, floats, and doubles.

ConstantValueDescription
QTextStream::ShowBase 0x1 Show the base as a prefix if the base is 16 ("0x"), 8 ("0"), or 2 ("0b").
QTextStream::ForcePoint 0x2 Always put the decimal separator in numbers, even if there are no decimals.
QTextStream::ForceSign 0x4 Always put the sign in numbers, even for positive numbers.
QTextStream::UppercaseBase 0x8 Use uppercase versions of base prefixes ("0X", "0B").
QTextStream::UppercaseDigits 0x10 Use uppercase letters for expressing digits 10 to 35 instead of lowercase.

See also setNumberFlags().

Look up this member in the source code.

Toggle detailsenum QTextStream::

RealNumberNotationRealNumberNotation { SmartNotation , FixedNotation , ScientificNotation 2 ...} { SmartNotation , FixedNotation , ScientificNotation 2 }

This enum specifies which notations to use for expressing float and double as strings.

ConstantValueDescription
QTextStream::ScientificNotation 2 Scientific notation (printf()'s %e flag).
QTextStream::FixedNotation 1 Fixed-point notation (printf()'s %f flag).
QTextStream::SmartNotation 0 Scientific or fixed-point notation, depending on which makes most sense (printf()'s %g flag).

See also setRealNumberNotation().

Look up this member in the source code.

Toggle detailsenum QTextStream::

StatusStatus { Ok , ReadPastEnd , ReadCorruptData 2 ...} { Ok , ReadPastEnd , ReadCorruptData 2 }

This enum describes the current status of the text stream.

ConstantValueDescription
QTextStream::Ok 0 The text stream is operating normally.
QTextStream::ReadPastEnd 1 The text stream has read past the end of the data in the underlying device.
QTextStream::ReadCorruptData 2 The text stream has read corrupt data.

See also status().

Look up this member in the source code.

Toggle detailsenum QTextStream::

EncodingEncoding { Locale , Latin1 , Unicode , UnicodeNetworkOrder , UnicodeReverse , RawUnicode , UnicodeUTF8 6 ...} { Locale , Latin1 , Unicode , UnicodeNetworkOrder , UnicodeReverse , RawUnicode , UnicodeUTF8 6 }Qt3-support

ConstantValueDescription
QTextStream::Latin1 1 Use setCodec(QTextCodec::codecForName("ISO-8859-1")) instead.
QTextStream::Locale 0 Use setCodec(QTextCodec::codecForLocale()) instead.
QTextStream::RawUnicode 5 Use setCodec(QTextCodec::codecForName("UTF-16")) instead.
QTextStream::Unicode 2 Use setCodec(QTextCodec::codecForName("UTF-16")) instead.
QTextStream::UnicodeNetworkOrder 3 Use setCodec(QTextCodec::codecForName("UTF-16BE")) instead.
QTextStream::UnicodeReverse 4 Use setCodec(QTextCodec::codecForName("UTF-16LE")) instead.
QTextStream::UnicodeUTF8 6 Use setCodec(QTextCodec::codecForName("UTF-8")) instead.

Also, for all encodings except QTextStream::Latin1 and QTextStream::UTF8, you need to call setAutoDetectUnicode(false) to obtain the Qt 3 behavior in addition to the setCodec() call.

See also setCodec() and setAutoDetectUnicode().

Look up this member in the source code.

Properties

Qt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-supportQt3-support
Toggle detailsadjustfieldadjustfield : const int

Use the new QTextStream manipulators instead.

Access functions:

    Look up this member in the source code.

    Toggle detailsbasefieldbasefield : const int

    Use the new QTextStream manipulators instead.

    Access functions:

      Look up this member in the source code.

      Toggle detailsbinbin : const int

      Use the new QTextStream manipulators instead.

      Access functions:

        Look up this member in the source code.

        Toggle detailsdecdec : const int

        Use the new QTextStream manipulators instead.

        Access functions:

          Look up this member in the source code.

          Toggle detailsfixedfixed : const int

          Use the new QTextStream manipulators instead.

          Access functions:

            Look up this member in the source code.

            Toggle detailsfloatfieldfloatfield : const int

            Use the new QTextStream manipulators instead.

            Access functions:

              Look up this member in the source code.

              Toggle detailshexhex : const int

              Use the new QTextStream manipulators instead.

              Access functions:

                Look up this member in the source code.

                Toggle detailsinternalinternal : const int

                Use the new QTextStream manipulators instead.

                Access functions:

                  Look up this member in the source code.

                  Toggle detailsleftleft : const int

                  Use the new QTextStream manipulators instead.

                  Access functions:

                    Look up this member in the source code.

                    Toggle detailsoctoct : const int

                    Use the new QTextStream manipulators instead.

                    Access functions:

                      Look up this member in the source code.

                      Toggle detailsrightright : const int

                      Use the new QTextStream manipulators instead.

                      Access functions:

                        Look up this member in the source code.

                        Toggle detailsscientificscientific : const int

                        Use the new QTextStream manipulators instead.

                        Access functions:

                          Look up this member in the source code.

                          Toggle detailsshowbaseshowbase : const int

                          Use the new QTextStream manipulators instead.

                          Access functions:

                            Look up this member in the source code.

                            Toggle detailsshowpointshowpoint : const int

                            Use the new QTextStream manipulators instead.

                            Access functions:

                              Look up this member in the source code.

                              Toggle detailsshowposshowpos : const int

                              Use the new QTextStream manipulators instead.

                              Access functions:

                                Look up this member in the source code.

                                Toggle detailsskipwsskipws : const int

                                Use the new QTextStream manipulators instead.

                                Access functions:

                                  Look up this member in the source code.

                                  Toggle detailsuppercaseuppercase : const int

                                  Use the new QTextStream manipulators instead.

                                  Access functions:

                                    Look up this member in the source code.

                                    Public Functions

                                    Toggle details QTextStream

                                    QTextStreamQTextStream () ()

                                    Constructs a QTextStream. Before you can use it for reading or writing, you must assign a device or a string.

                                    See also setDevice() and setString().

                                    Look up this member in the source code.

                                    Toggle details QTextStream

                                    QTextStreamQTextStream ( QIODevice *device ) ( QIODevice *device )

                                    Constructs a QTextStream that operates on device.

                                    Look up this member in the source code.

                                    Toggle details QTextStream

                                    QTextStreamQTextStream ( FILE *fileHandle , QIODevice::OpenMode openMode=QIODevice::ReadWrite ...) ( FILE *fileHandle , QIODevice::OpenMode openMode=QIODevice::ReadWrite )

                                    Constructs a QTextStream that operates on fileHandle, using openMode to define the open mode. Internally, a QFile is created to handle the FILE pointer.

                                    This constructor is useful for working directly with the common FILE based input and output streams: stdin, stdout and stderr. Example:

                                    1.                     QString str;
                                    2. QTextStream in(stdin);
                                    3. in >> str;

                                    Look up this member in the source code.

                                    Toggle details QTextStream

                                    QTextStreamQTextStream ( QString *string , QIODevice::OpenMode openMode=QIODevice::ReadWrite ...) ( QString *string , QIODevice::OpenMode openMode=QIODevice::ReadWrite )

                                    Constructs a QTextStream that operates on string, using openMode to define the open mode.

                                    Look up this member in the source code.

                                    Toggle details QTextStream

                                    QTextStreamQTextStream ( QByteArray *array , QIODevice::OpenMode openMode=QIODevice::ReadWrite ...) ( QByteArray *array , QIODevice::OpenMode openMode=QIODevice::ReadWrite )

                                    Constructs a QTextStream that operates on array, using openMode to define the open mode. Internally, the array is wrapped by a QBuffer.

                                    Look up this member in the source code.

                                    Toggle details QTextStream

                                    QTextStreamQTextStream ( const QByteArray &array , QIODevice::OpenMode openMode=QIODevice::ReadOnly ...) ( const QByteArray &array , QIODevice::OpenMode openMode=QIODevice::ReadOnly )

                                    Constructs a QTextStream that operates on array, using openMode to define the open mode. The array is accessed as read-only, regardless of the values in openMode.

                                    This constructor is convenient for working on constant strings. Example:

                                    1. int main(int argc, char *argv[])
                                    2.  {
                                    3.     // read numeric arguments (123, 0x20, 4.5...)
                                    4.     for (int i = 1; i < argc; ++i)  {
                                    5.           int number;
                                    6.           QTextStream in(argv[i]);
                                    7.           in >> number;
                                    8.           ...
                                    9.     }
                                    10. }

                                    Look up this member in the source code.

                                    Toggle details QTextStream

                                    ~QTextStream~QTextStream () () [virtual]

                                    Destroys the QTextStream.

                                    If the stream operates on a device, flush() will be called implicitly. Otherwise, the device is unaffected.

                                    Look up this member in the source code.

                                    Toggle details bool QTextStream

                                    atEndatEnd () ()const

                                    Returns true if there is no more data to be read from the QTextStream; otherwise returns false. This is similar to, but not the same as calling QIODevice::atEnd(), as QTextStream also takes into account its internal Unicode buffer.

                                    Look up this member in the source code.

                                    Toggle details bool QTextStream

                                    autoDetectUnicodeautoDetectUnicode () ()const

                                    Returns true if automatic Unicode detection is enabled, otherwise returns false. Automatic Unicode detection is enabled by default.

                                    See also setAutoDetectUnicode() and setCodec().

                                    Look up this member in the source code.

                                    Toggle details QTextCodec * QTextStream

                                    codeccodec () ()const

                                    Returns the codec that is current assigned to the stream.

                                    See also setCodec(), setAutoDetectUnicode(), and locale().

                                    Look up this member in the source code.

                                    Toggle details QIODevice * QTextStream

                                    devicedevice () ()const

                                    Returns the current device associated with the QTextStream, or 0 if no device has been assigned.

                                    See also setDevice() and string().

                                    Look up this member in the source code.

                                    Toggle details FieldAlignment QTextStream

                                    fieldAlignmentfieldAlignment () ()const

                                    Returns the current field alignment.

                                    See also setFieldAlignment() and fieldWidth().

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    fieldWidthfieldWidth () ()const

                                    Returns the current field width.

                                    See also setFieldWidth().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    flushflush () ()

                                    Flushes any buffered data waiting to be written to the device.

                                    If QTextStream operates on a string, this function does nothing.

                                    Look up this member in the source code.

                                    Toggle details bool QTextStream

                                    generateByteOrderMarkgenerateByteOrderMark () ()const

                                    Returns true if QTextStream is set to generate the UTF BOM (Byte Order Mark) when using a UTF codec; otherwise returns false. UTF BOM generation is set to false by default.

                                    See also setGenerateByteOrderMark().

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    integerBaseintegerBase () ()const

                                    Returns the current base of integers. 0 means that the base is detected when reading, or 10 (decimal) when generating numbers.

                                    See also setIntegerBase(), QString::number(), and numberFlags().

                                    Look up this member in the source code.

                                    Toggle details QLocale QTextStream

                                    localelocale () ()const

                                    Returns the locale for this stream. The default locale is C.

                                    See also setLocale().

                                    Look up this member in the source code.

                                    Toggle details NumberFlags QTextStream

                                    numberFlagsnumberFlags () ()const

                                    Returns the current number flags.

                                    See also setNumberFlags(), integerBase(), and realNumberNotation().

                                    Look up this member in the source code.

                                    Toggle details QChar QTextStream

                                    padCharpadChar () ()const

                                    Returns the current pad character.

                                    See also setPadChar() and setFieldWidth().

                                    Look up this member in the source code.

                                    Toggle details qint64 QTextStream

                                    pospos () ()const

                                    Returns the device position corresponding to the current position of the stream, or -1 if an error occurs (e.g., if there is no device or string, or if there's a device error).

                                    Because QTextStream is buffered, this function may have to seek the device to reconstruct a valid device position. This operation can be expensive, so you may want to avoid calling this function in a tight loop.

                                    See also seek().

                                    Look up this member in the source code.

                                    Toggle details QString QTextStream

                                    readread ( qint64 maxlen ) ( qint64 maxlen )

                                    Reads at most maxlen characters from the stream, and returns the data read as a QString.

                                    See also readAll(), readLine(), and QIODevice::read().

                                    Look up this member in the source code.

                                    Toggle details QString QTextStream

                                    readAllreadAll () ()

                                    Reads the entire content of the stream, and returns it as a QString. Avoid this function when working on large files, as it will consume a significant amount of memory.

                                    Calling readLine() is better if you do not know how much data is available.

                                    See also readLine().

                                    Look up this member in the source code.

                                    Toggle details QString QTextStream

                                    readLinereadLine ( qint64 maxlen=0 ) ( qint64 maxlen=0 )

                                    Reads one line of text from the stream, and returns it as a QString. The maximum allowed line length is set to maxlen. If the stream contains lines longer than this, then the lines will be split after maxlen characters and returned in parts.

                                    If maxlen is 0, the lines can be of any length. A common value for maxlen is 75.

                                    The returned line has no trailing end-of-line characters ("\n" or "\r\n"), so calling QString::trimmed() is unnecessary.

                                    If the stream has read to the end of the file, readLine() will return a null QString. For strings, or for devices that support it, you can explicitly test for the end of the stream using atEnd().

                                    See also readAll() and QIODevice::readLine().

                                    Look up this member in the source code.

                                    Toggle details RealNumberNotation QTextStream

                                    realNumberNotationrealNumberNotation () ()const

                                    Returns the current real number notation.

                                    See also setRealNumberNotation(), realNumberPrecision(), numberFlags(), and integerBase().

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    realNumberPrecisionrealNumberPrecision () ()const

                                    Returns the current real number precision, or the number of fraction digits QTextStream will write when generating real numbers.

                                    See also setRealNumberPrecision(), setRealNumberNotation(), realNumberNotation(), numberFlags(), and integerBase().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    resetreset () ()

                                    Resets QTextStream's formatting options, bringing it back to its original constructed state. The device, string and any buffered data is left untouched.

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    resetStatusresetStatus () ()

                                    Resets the status of the text stream.

                                    See also QTextStream::Status, status(), and setStatus().

                                    Look up this member in the source code.

                                    Toggle details bool QTextStream

                                    seekseek ( qint64 pos ) ( qint64 pos )

                                    Seeks to the position pos in the device. Returns true on success; otherwise returns false.

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setAutoDetectUnicodesetAutoDetectUnicode ( bool enabled ) ( bool enabled )

                                    If enabled is true, QTextStream will attempt to detect Unicode encoding by peeking into the stream data to see if it can find the UTF-16 or UTF-32 BOM (Byte Order Mark). If this mark is found, QTextStream will replace the current codec with the UTF codec.

                                    This function can be used together with setCodec(). It is common to set the codec to UTF-8, and then enable UTF-16 detection.

                                    See also autoDetectUnicode() and setCodec().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setCodecsetCodec ( QTextCodec *codec ) ( QTextCodec *codec )

                                    Sets the codec for this stream to codec. The codec is used for decoding any data that is read from the assigned device, and for encoding any data that is written. By default, QTextCodec::codecForLocale() is used, and automatic unicode detection is enabled.

                                    If QTextStream operates on a string, this function does nothing.

                                    Warning: If you call this function while the text stream is reading from an open sequential socket, the internal buffer may still contain text decoded using the old codec.

                                    See also codec(), setAutoDetectUnicode(), and setLocale().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setCodecsetCodec ( const char *codecName ) ( const char *codecName )

                                    Sets the codec for this stream to the QTextCodec for the encoding specified by codecName. Common values for codecName include "ISO 8859-1", "UTF-8", and "UTF-16". If the encoding isn't recognized, nothing happens.

                                    Example:

                                    1.                     QTextStream out(&file);
                                    2. out.setCodec("UTF-8");

                                    See also QTextCodec::codecForName() and setLocale().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setDevicesetDevice ( QIODevice *device ) ( QIODevice *device )

                                    Sets the current device to device. If a device has already been assigned, QTextStream will call flush() before the old device is replaced.

                                    Note: This function resets locale to the default locale ('C') and codec to the default codec, QTextCodec::codecForLocale().

                                    See also device() and setString().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setFieldAlignmentsetFieldAlignment ( FieldAlignment mode ) ( FieldAlignment mode )

                                    Sets the field alignment to mode. When used together with setFieldWidth(), this function allows you to generate formatted output with text aligned to the left, to the right or center aligned.

                                    See also fieldAlignment() and setFieldWidth().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setFieldWidthsetFieldWidth ( int width ) ( int width )

                                    Sets the current field width to width. If width is 0 (the default), the field width is equal to the length of the generated text.

                                    Note: The field width applies to every element appended to this stream after this function has been called (e.g., it also pads endl). This behavior is different from similar classes in the STL, where the field width only applies to the next element.

                                    See also fieldWidth() and setPadChar().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setGenerateByteOrderMarksetGenerateByteOrderMark ( bool generate ) ( bool generate )

                                    If generate is true and a UTF codec is used, QTextStream will insert the BOM (Byte Order Mark) before any data has been written to the device. If generate is false, no BOM will be inserted. This function must be called before any data is written. Otherwise, it does nothing.

                                    See also generateByteOrderMark() and bom().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setIntegerBasesetIntegerBase ( int base ) ( int base )

                                    Sets the base of integers to base, both for reading and for generating numbers. base can be either 2 (binary), 8 (octal), 10 (decimal) or 16 (hexadecimal). If base is 0, QTextStream will attempt to detect the base by inspecting the data on the stream. When generating numbers, QTextStream assumes base is 10 unless the base has been set explicitly.

                                    See also integerBase(), QString::number(), and setNumberFlags().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setLocalesetLocale ( const QLocale &locale ) ( const QLocale &locale )

                                    Sets the locale for this stream to locale. The specified locale is used for conversions between numbers and their string representations.

                                    The default locale is C and it is a special case - the thousands group separator is not used for backward compatibility reasons.

                                    See also locale().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setNumberFlagssetNumberFlags ( NumberFlags flags ) ( NumberFlags flags )

                                    Sets the current number flags to flags. flags is a set of flags from the NumberFlag enum, and describes options for formatting generated code (e.g., whether or not to always write the base or sign of a number).

                                    See also numberFlags(), setIntegerBase(), and setRealNumberNotation().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setPadCharsetPadChar ( QChar ch ) ( QChar ch )

                                    Sets the pad character to ch. The default value is the ASCII space character (' '), or QChar(0x20). This character is used to fill in the space in fields when generating text.

                                    Example:

                                    1.                     QString s;
                                    2. QTextStream out(&s);
                                    3. out.setFieldWidth(10);
                                    4. out.setFieldAlignment(QTextStream::AlignCenter);
                                    5. out.setPadChar('-');
                                    6. out << "Qt" << "rocks!";

                                    The string s contains:

                                    1. ----Qt------rocks!--

                                    See also padChar() and setFieldWidth().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setRealNumberNotationsetRealNumberNotation ( RealNumberNotation notation ...) ( RealNumberNotation notation )

                                    Sets the real number notation to notation (SmartNotation, FixedNotation, ScientificNotation). When reading and generating numbers, QTextStream uses this value to detect the formatting of real numbers.

                                    See also realNumberNotation(), setRealNumberPrecision(), setNumberFlags(), and setIntegerBase().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setRealNumberPrecisionsetRealNumberPrecision ( int precision ) ( int precision )

                                    Sets the precision of real numbers to precision. This value describes the number of fraction digits QTextStream should write when generating real numbers.

                                    The precision cannot be a negative value. The default value is 6.

                                    See also realNumberPrecision() and setRealNumberNotation().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setStatussetStatus ( Status status ) ( Status status )

                                    Sets the status of the text stream to the status given.

                                    See also Status, status(), and resetStatus().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setStringsetString ( QString *string , QIODevice::OpenMode openMode=QIODevice::ReadWrite ...) ( QString *string , QIODevice::OpenMode openMode=QIODevice::ReadWrite )

                                    Sets the current string to string, using the given openMode. If a device has already been assigned, QTextStream will call flush() before replacing it.

                                    See also string() and setDevice().

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    skipWhiteSpaceskipWhiteSpace () ()

                                    Reads and discards whitespace from the stream until either a non-space character is detected, or until atEnd() returns true. This function is useful when reading a stream character by character.

                                    Whitespace characters are all characters for which QChar::isSpace() returns true.

                                    See also operator>>().

                                    Look up this member in the source code.

                                    Toggle details Status QTextStream

                                    statusstatus () ()const

                                    Returns the status of the text stream.

                                    See also QTextStream::Status, setStatus(), and resetStatus().

                                    Look up this member in the source code.

                                    Toggle details QString * QTextStream

                                    stringstring () ()const

                                    Returns the current string assigned to the QTextStream, or 0 if no string has been assigned.

                                    See also setString() and device().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( QChar c ) ( QChar c )

                                    Writes the character c to the stream, then returns a reference to the QTextStream.

                                    See also setFieldWidth().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( signed shorti ) ( signed shorti )

                                    Writes the integer number i to the stream, then returns a reference to the QTextStream. By default, the number is stored in decimal form, but you can also set the base by calling setIntegerBase().

                                    See also setFieldWidth() and setNumberFlags().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( floatf ) ( floatf )

                                    Writes the real number f to the stream, then returns a reference to the QTextStream. By default, QTextStream stores it using SmartNotation, with up to 6 digits of precision. You can change the textual representation QTextStream will use for real numbers by calling setRealNumberNotation(), setRealNumberPrecision() and setNumberFlags().

                                    See also setFieldWidth(), setRealNumberNotation(), setRealNumberPrecision(), and setNumberFlags().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( const QString &string ) ( const QString &string )

                                    Writes the string string to the stream, and returns a reference to the QTextStream. The string is first encoded using the assigned codec (the default codec is QTextCodec::codecForLocale()) before it is written to the stream.

                                    See also setFieldWidth() and setCodec().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( charc ) ( charc )

                                    This is an overloaded function.

                                    Converts c from ASCII to a QChar, then writes it to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( unsigned shorti ) ( unsigned shorti )

                                    This is an overloaded function.

                                    Writes the unsigned short i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( signed int i ) ( signed int i )

                                    This is an overloaded function.

                                    Writes the signed int i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( unsigned int i ) ( unsigned int i )

                                    This is an overloaded function.

                                    Writes the unsigned int i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( signed longi ) ( signed longi )

                                    This is an overloaded function.

                                    Writes the signed long i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( unsigned longi ) ( unsigned longi )

                                    This is an overloaded function.

                                    Writes the unsigned long i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( qlonglong i ) ( qlonglong i )

                                    This is an overloaded function.

                                    Writes the qlonglong i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( qulonglong i ) ( qulonglong i )

                                    This is an overloaded function.

                                    Writes the qulonglong i to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( double f ) ( double f )

                                    This is an overloaded function.

                                    Writes the double f to the stream.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( const QByteArray &array ) ( const QByteArray &array )

                                    This is an overloaded function.

                                    Writes array to the stream. The contents of array are converted with QString::fromAscii().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( const char *string ) ( const char *string )

                                    This is an overloaded function.

                                    Writes the constant string pointed to by string to the stream. string is assumed to be in ISO-8859-1 encoding. This operator is convenient when working with constant string data. Example:

                                    1.                     QTextStream out(stdout);
                                    2. out << "Qt rocks!" << endl;

                                    Warning: QTextStream assumes that string points to a string of text, terminated by a '\0' character. If there is no terminating '\0' character, your application may crash.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator<<operator<< ( const void *ptr ) ( const void *ptr )

                                    This is an overloaded function.

                                    Writes ptr to the stream as a hexadecimal number with a base.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( QChar &c ) ( QChar &c )

                                    Reads a character from the stream and stores it in c. Returns a reference to the QTextStream, so several operators can be nested. Example:

                                    1.                     QTextStream in(file);
                                    2. QChar ch1, ch2, ch3;
                                    3. in >> ch1 >> ch2 >> ch3;

                                    Whitespace is not skipped.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( signed short &i ) ( signed short &i )

                                    Reads an integer from the stream and stores it in i, then returns a reference to the QTextStream. The number is cast to the correct type before it is stored. If no number was detected on the stream, i is set to 0.

                                    By default, QTextStream will attempt to detect the base of the number using the following rules:

                                    PrefixBase
                                    "0b" or "0B"2 (binary)
                                    "0" followed by "0-7"8 (octal)
                                    "0" otherwise10 (decimal)
                                    "0x" or "0X"16 (hexadecimal)
                                    "1" to "9"10 (decimal)

                                    By calling setIntegerBase(), you can specify the integer base explicitly. This will disable the auto-detection, and speed up QTextStream slightly.

                                    Leading whitespace is skipped.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( float &f ) ( float &f )

                                    Reads a real number from the stream and stores it in f, then returns a reference to the QTextStream. The number is cast to the correct type. If no real number is detect on the stream, f is set to 0.0.

                                    As a special exception, QTextStream allows the strings "nan" and "inf" to represent NAN and INF floats or doubles.

                                    Leading whitespace is skipped.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( QString &str ) ( QString &str )

                                    Reads a word from the stream and stores it in str, then returns a reference to the stream. Words are separated by whitespace (i.e., all characters for which QChar::isSpace() returns true).

                                    Leading whitespace is skipped.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( char &c ) ( char &c )

                                    This is an overloaded function.

                                    Reads a character from the stream and stores it in c. The character from the stream is converted to ISO-5589-1 before it is stored.

                                    See also QChar::toLatin1().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( unsigned short &i ) ( unsigned short &i )

                                    This is an overloaded function.

                                    Stores the integer in the unsigned short i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( signed int &i ) ( signed int &i )

                                    This is an overloaded function.

                                    Stores the integer in the signed int i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( unsigned int &i ) ( unsigned int &i )

                                    This is an overloaded function.

                                    Stores the integer in the unsigned int i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( signed long &i ) ( signed long &i )

                                    This is an overloaded function.

                                    Stores the integer in the signed long i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( unsigned long &i ) ( unsigned long &i )

                                    This is an overloaded function.

                                    Stores the integer in the unsigned long i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( qlonglong &i ) ( qlonglong &i )

                                    This is an overloaded function.

                                    Stores the integer in the qlonglong i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( qulonglong &i ) ( qulonglong &i )

                                    This is an overloaded function.

                                    Stores the integer in the qulonglong i.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( double &f ) ( double &f )

                                    This is an overloaded function.

                                    Stores the real number in the double f.

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( QByteArray &array ) ( QByteArray &array )

                                    This is an overloaded function.

                                    Converts the word to ISO-8859-1, then stores it in array.

                                    See also QString::toLatin1().

                                    Look up this member in the source code.

                                    Toggle details QTextStream & QTextStream

                                    operator>>operator>> ( char *c ) ( char *c )

                                    This is an overloaded function.

                                    Stores the word in c, terminated by a '\0' character. If no word is available, only the '\0' character is stored.

                                    Warning: Although convenient, this operator is dangerous and must be used with care. QTextStream assumes that c points to a buffer with enough space to hold the word. If the buffer is too small, your application may crash.

                                    If possible, use the QByteArray operator instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    fillfill ( int f ) ( int f ) Qt3-support

                                    Use setPadChar() instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    flagsflags () ()const Qt3-support

                                    Use fieldAlignment(), padChar(), fieldWidth(), numberFlags(), integerBase(), realNumberNotation(), and realNumberNotation instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    flagsflags ( int f ) ( int f ) Qt3-support

                                    Use setFieldAlignment(), setPadChar(), setFieldWidth(), setNumberFlags(), setIntegerBase(), setRealNumberNotation(), and setRealNumberNotation instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    precisionprecision ( int p ) ( int p ) Qt3-support

                                    Use setRealNumberPrecision() instead.

                                    Look up this member in the source code.

                                    Toggle details QString QTextStream

                                    readread () () Qt3-support

                                    Use readAll() or readLine() instead.

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    setEncodingsetEncoding ( Encoding encoding ) ( Encoding encoding ) Qt3-support

                                    Use setCodec() and setAutoDetectUnicode() instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    setfsetf ( int bits ) ( int bits ) Qt3-support

                                    Use setFieldAlignment(), setPadChar(), setFieldWidth(), setNumberFlags(), setIntegerBase(), setRealNumberNotation(), and setRealNumberNotation instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    setfsetf ( int bits , int mask ) ( int bits , int mask ) Qt3-support

                                    Use setFieldAlignment(), setPadChar(), setFieldWidth(), setNumberFlags(), setIntegerBase(), setRealNumberNotation(), and setRealNumberNotation instead.

                                    Look up this member in the source code.

                                    Toggle details void QTextStream

                                    unsetDeviceunsetDevice () () Qt3-support

                                    Use setDevice(0) instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    unsetfunsetf ( int bits ) ( int bits ) Qt3-support

                                    Use setFieldAlignment(), setPadChar(), setFieldWidth(), setNumberFlags(), setIntegerBase(), setRealNumberNotation(), and setRealNumberNotation instead.

                                    Look up this member in the source code.

                                    Toggle details int QTextStream

                                    widthwidth ( int w ) ( int w ) Qt3-support

                                    Use setFieldWidth() instead.

                                    Look up this member in the source code.

                                    Notes provided by the Qt Community

                                    No notes