Qt 4.8
|
The QTextStream class provides a convenient interface for reading and writing text. More...
#include <qtextstream.h>
Public Types | |
enum | FieldAlignment { AlignLeft, AlignRight, AlignCenter, AlignAccountingStyle } |
This enum specifies how to align text in fields when the field is wider than the text that occupies it. More... | |
enum | NumberFlag { ShowBase = 0x1, ForcePoint = 0x2, ForceSign = 0x4, UppercaseBase = 0x8, UppercaseDigits = 0x10 } |
This enum specifies various flags that can be set to affect the output of integers, float s, and double s. More... | |
enum | RealNumberNotation { SmartNotation, FixedNotation, ScientificNotation } |
This enum specifies which notations to use for expressing float and double as strings. More... | |
enum | Status { Ok, ReadPastEnd, ReadCorruptData, WriteFailed } |
This enum describes the current status of the text stream. More... | |
Public Functions | |
bool | atEnd () const |
Returns true if there is no more data to be read from the QTextStream; otherwise returns false. More... | |
bool | autoDetectUnicode () const |
Returns true if automatic Unicode detection is enabled, otherwise returns false. More... | |
QTextCodec * | codec () const |
Returns the codec that is current assigned to the stream. More... | |
QIODevice * | device () const |
Returns the current device associated with the QTextStream, or 0 if no device has been assigned. More... | |
FieldAlignment | fieldAlignment () const |
Returns the current field alignment. More... | |
int | fieldWidth () const |
Returns the current field width. More... | |
void | flush () |
Flushes any buffered data waiting to be written to the device. More... | |
bool | generateByteOrderMark () const |
Returns true if QTextStream is set to generate the UTF BOM (Byte Order Mark) when using a UTF codec; otherwise returns false. More... | |
int | integerBase () const |
Returns the current base of integers. More... | |
QLocale | locale () const |
Returns the locale for this stream. More... | |
NumberFlags | numberFlags () const |
Returns the current number flags. More... | |
QTextStream & | operator<< (QBool b) |
QTextStream & | operator<< (QChar ch) |
Writes the character c to the stream, then returns a reference to the QTextStream. More... | |
QTextStream & | operator<< (char ch) |
Converts c from ASCII to a QChar, then writes it to the stream. More... | |
QTextStream & | operator<< (signed short i) |
Writes the integer number i to the stream, then returns a reference to the QTextStream. More... | |
QTextStream & | operator<< (unsigned short i) |
Writes the unsigned short i to the stream. More... | |
QTextStream & | operator<< (signed int i) |
Writes the signed int i to the stream. More... | |
QTextStream & | operator<< (unsigned int i) |
Writes the unsigned int i to the stream. More... | |
QTextStream & | operator<< (signed long i) |
Writes the signed long i to the stream. More... | |
QTextStream & | operator<< (unsigned long i) |
Writes the unsigned long i to the stream. More... | |
QTextStream & | operator<< (qlonglong i) |
Writes the qlonglong i to the stream. More... | |
QTextStream & | operator<< (qulonglong i) |
Writes the qulonglong i to the stream. More... | |
QTextStream & | operator<< (float f) |
Writes the real number f to the stream, then returns a reference to the QTextStream. More... | |
QTextStream & | operator<< (double f) |
Writes the double f to the stream. More... | |
QTextStream & | operator<< (const QString &s) |
Writes the string string to the stream, and returns a reference to the QTextStream. More... | |
QTextStream & | operator<< (const QByteArray &array) |
Writes array to the stream. More... | |
QTextStream & | operator<< (const char *c) |
Writes the constant string pointed to by string to the stream. More... | |
QTextStream & | operator<< (const void *ptr) |
Writes ptr to the stream as a hexadecimal number with a base. More... | |
QTextStream & | operator>> (QChar &ch) |
Reads a character from the stream and stores it in c. More... | |
QTextStream & | operator>> (char &ch) |
Reads a character from the stream and stores it in c. More... | |
QTextStream & | operator>> (signed short &i) |
Reads an integer from the stream and stores it in i, then returns a reference to the QTextStream. More... | |
QTextStream & | operator>> (unsigned short &i) |
Stores the integer in the unsigned short i. More... | |
QTextStream & | operator>> (signed int &i) |
Stores the integer in the signed int i. More... | |
QTextStream & | operator>> (unsigned int &i) |
Stores the integer in the unsigned int i. More... | |
QTextStream & | operator>> (signed long &i) |
Stores the integer in the signed long i. More... | |
QTextStream & | operator>> (unsigned long &i) |
Stores the integer in the unsigned long i. More... | |
QTextStream & | operator>> (qlonglong &i) |
Stores the integer in the qlonglong i. More... | |
QTextStream & | operator>> (qulonglong &i) |
Stores the integer in the qulonglong i. More... | |
QTextStream & | operator>> (float &f) |
Reads a real number from the stream and stores it in f, then returns a reference to the QTextStream. More... | |
QTextStream & | operator>> (double &f) |
Stores the real number in the double f. More... | |
QTextStream & | operator>> (QString &s) |
Reads a word from the stream and stores it in str, then returns a reference to the stream. More... | |
QTextStream & | operator>> (QByteArray &array) |
Converts the word to ISO-8859-1, then stores it in array. More... | |
QTextStream & | operator>> (char *c) |
Stores the word in c, terminated by a '\0' character. More... | |
QChar | padChar () const |
Returns the current pad character. More... | |
qint64 | pos () const |
Returns the device position corresponding to the current position of the stream, or -1 if an error occurs (e. More... | |
QTextStream () | |
Constructs a QTextStream. More... | |
QTextStream (QIODevice *device) | |
Constructs a QTextStream that operates on device. More... | |
QTextStream (FILE *fileHandle, QIODevice::OpenMode openMode=QIODevice::ReadWrite) | |
Constructs a QTextStream that operates on fileHandle, using openMode to define the open mode. More... | |
QTextStream (QString *string, QIODevice::OpenMode openMode=QIODevice::ReadWrite) | |
Constructs a QTextStream that operates on string, using openMode to define the open mode. More... | |
QTextStream (QByteArray *array, QIODevice::OpenMode openMode=QIODevice::ReadWrite) | |
Constructs a QTextStream that operates on array, using openMode to define the open mode. More... | |
QTextStream (const QByteArray &array, QIODevice::OpenMode openMode=QIODevice::ReadOnly) | |
Constructs a QTextStream that operates on array, using openMode to define the open mode. More... | |
QString | read (qint64 maxlen) |
Reads at most maxlen characters from the stream, and returns the data read as a QString. More... | |
QString | readAll () |
Reads the entire content of the stream, and returns it as a QString. More... | |
QString | readLine (qint64 maxlen=0) |
Reads one line of text from the stream, and returns it as a QString. More... | |
RealNumberNotation | realNumberNotation () const |
Returns the current real number notation. More... | |
int | realNumberPrecision () const |
Returns the current real number precision, or the number of fraction digits QTextStream will write when generating real numbers. More... | |
void | reset () |
Resets QTextStream's formatting options, bringing it back to its original constructed state. More... | |
void | resetStatus () |
Resets the status of the text stream. More... | |
bool | seek (qint64 pos) |
Seeks to the position pos in the device. More... | |
void | setAutoDetectUnicode (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). More... | |
void | setCodec (QTextCodec *codec) |
Sets the codec for this stream to codec. More... | |
void | setCodec (const char *codecName) |
Sets the codec for this stream to the QTextCodec for the encoding specified by codecName. More... | |
void | setDevice (QIODevice *device) |
Sets the current device to device. More... | |
void | setFieldAlignment (FieldAlignment alignment) |
Sets the field alignment to mode. More... | |
void | setFieldWidth (int width) |
Sets the current field width to width. More... | |
void | setGenerateByteOrderMark (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. More... | |
void | setIntegerBase (int base) |
Sets the base of integers to base, both for reading and for generating numbers. More... | |
void | setLocale (const QLocale &locale) |
Sets the locale for this stream to locale. More... | |
void | setNumberFlags (NumberFlags flags) |
Sets the current number flags to flags. More... | |
void | setPadChar (QChar ch) |
Sets the pad character to ch. More... | |
void | setRealNumberNotation (RealNumberNotation notation) |
Sets the real number notation to notation (SmartNotation, FixedNotation, ScientificNotation). More... | |
void | setRealNumberPrecision (int precision) |
Sets the precision of real numbers to precision. More... | |
void | setStatus (Status status) |
Sets the status of the text stream to the status given. More... | |
void | setString (QString *string, QIODevice::OpenMode openMode=QIODevice::ReadWrite) |
Sets the current string to string, using the given openMode. More... | |
void | skipWhiteSpace () |
Reads and discards whitespace from the stream until either a non-space character is detected, or until atEnd() returns true. More... | |
Status | status () const |
Returns the status of the text stream. More... | |
QString * | string () const |
Returns the current string assigned to the QTextStream, or 0 if no string has been assigned. More... | |
virtual | ~QTextStream () |
Destroys the QTextStream. More... | |
Properties | |
QScopedPointer< QTextStreamPrivate > | d_ptr |
Related Functions | |
(Note that these are not member functions.) | |
QTextStream & | bin (QTextStream &stream) |
Calls QTextStream::setIntegerBase(2) on stream and returns stream. More... | |
QTextStream & | bom (QTextStream &stream) |
Toggles insertion of the Byte Order Mark on stream when QTextStream is used with a UTF codec. More... | |
QTextStream & | center (QTextStream &stream) |
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream. More... | |
QTextStream & | dec (QTextStream &stream) |
Calls QTextStream::setIntegerBase(10) on stream and returns stream. More... | |
QTextStream & | endl (QTextStream &stream) |
Writes ' ' to the stream and flushes the stream. More... | |
QTextStream & | fixed (QTextStream &stream) |
Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream. More... | |
QTextStream & | flush (QTextStream &stream) |
Calls QTextStream::flush() on stream and returns stream. More... | |
QTextStream & | forcepoint (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForcePoint) on stream and returns stream. More... | |
QTextStream & | forcesign (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and returns stream. More... | |
QTextStream & | hex (QTextStream &stream) |
Calls QTextStream::setIntegerBase(16) on stream and returns stream. More... | |
QTextStream & | left (QTextStream &stream) |
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream. More... | |
QTextStream & | lowercasebase (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseBase) on stream and returns stream. More... | |
QTextStream & | lowercasedigits (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseDigits) on stream and returns stream. More... | |
QTextStream & | noforcepoint (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForcePoint) on stream and returns stream. More... | |
QTextStream & | noforcesign (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and returns stream. More... | |
QTextStream & | noshowbase (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and returns stream. More... | |
QTextStream & | oct (QTextStream &stream) |
Calls QTextStream::setIntegerBase(8) on stream and returns stream. More... | |
QTextStreamManipulator | qSetFieldWidth (int width) |
Equivalent to QTextStream::setFieldWidth(width). More... | |
QTextStreamManipulator | qSetPadChar (QChar ch) |
Equivalent to QTextStream::setPadChar(ch). More... | |
QTextStreamManipulator | qSetRealNumberPrecision (int precision) |
Equivalent to QTextStream::setRealNumberPrecision(precision). More... | |
QTextStream & | reset (QTextStream &stream) |
Calls QTextStream::reset() on stream and returns stream. More... | |
QTextStream & | right (QTextStream &stream) |
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream. More... | |
QTextStream & | scientific (QTextStream &stream) |
Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) on stream and returns stream. More... | |
QTextStream & | showbase (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and returns stream. More... | |
QTextStream & | uppercasebase (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseBase) on stream and returns stream. More... | |
QTextStream & | uppercasedigits (QTextStream &stream) |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseDigits) on stream and returns stream. More... | |
QTextStream & | ws (QTextStream &stream) |
Calls skipWhiteSpace() on stream and returns stream. More... | |
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:
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:
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:
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().
QTextStream manipulators
Like <iostream> in the standard C++ library, QTextStream also defines several global manipulator functions:
Manipulator | Description |
bin | Same as setIntegerBase(2). |
oct | Same as setIntegerBase(8). |
dec | Same as setIntegerBase(10). |
hex | Same as setIntegerBase(16). |
showbase | Same as setNumberFlags(numberFlags() | ShowBase). |
forcesign | Same as setNumberFlags(numberFlags() | ForceSign). |
forcepoint | Same as setNumberFlags(numberFlags() | ForcePoint). |
noshowbase | Same as setNumberFlags(numberFlags() & ~ShowBase). |
noforcesign | Same as setNumberFlags(numberFlags() & ~ForceSign). |
noforcepoint | Same as setNumberFlags(numberFlags() & ~ForcePoint). |
uppercasebase | Same as setNumberFlags(numberFlags() | UppercaseBase). |
uppercasedigits | Same as setNumberFlags(numberFlags() | UppercaseDigits). |
lowercasebase | Same as setNumberFlags(numberFlags() & ~UppercaseBase). |
lowercasedigits | Same as setNumberFlags(numberFlags() & ~UppercaseDigits). |
fixed | Same as setRealNumberNotation(FixedNotation). |
scientific | Same as setRealNumberNotation(ScientificNotation). |
left | Same as setFieldAlignment(AlignLeft). |
right | Same as setFieldAlignment(AlignRight). |
center | Same as setFieldAlignment(AlignCenter). |
endl | Same as operator<<(' ') and flush(). |
flush | Same as flush(). |
reset | Same as reset(). |
ws | Same as skipWhiteSpace(). |
bom | Same as setGenerateByteOrderMark(true). |
In addition, Qt provides three global manipulators that take a parameter: qSetFieldWidth(), qSetPadChar(), and qSetRealNumberPrecision().
Definition at line 73 of file qtextstream.h.
This enum specifies how to align text in fields when the field is wider than the text that occupies it.
Enumerator | |
---|---|
AlignLeft | |
AlignRight | |
AlignCenter | |
AlignAccountingStyle |
Definition at line 83 of file qtextstream.h.
This enum specifies various flags that can be set to affect the output of integers, float
s, and double
s.
Enumerator | |
---|---|
ShowBase | |
ForcePoint | |
ForceSign | |
UppercaseBase | |
UppercaseDigits |
Definition at line 95 of file qtextstream.h.
This enum specifies which notations to use for expressing float
and double
as strings.
printf()
's e
flag). printf()
's f
flag). printf()
's g
flag).Enumerator | |
---|---|
SmartNotation | |
FixedNotation | |
ScientificNotation |
Definition at line 78 of file qtextstream.h.
enum QTextStream::Status |
This enum describes the current status of the text stream.
Enumerator | |
---|---|
Ok | |
ReadPastEnd | |
ReadCorruptData | |
WriteFailed |
Definition at line 89 of file qtextstream.h.
QTextStream::QTextStream | ( | ) |
Constructs a QTextStream.
Before you can use it for reading or writing, you must assign a device or a string.
Definition at line 1027 of file qtextstream.cpp.
Referenced by qSetRealNumberPrecision().
|
explicit |
Constructs a QTextStream that operates on device.
Definition at line 1040 of file qtextstream.cpp.
|
explicit |
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:
Definition at line 1135 of file qtextstream.cpp.
|
explicit |
Constructs a QTextStream that operates on string, using openMode to define the open mode.
Definition at line 1059 of file qtextstream.cpp.
|
explicit |
Constructs a QTextStream that operates on array, using openMode to define the open mode.
Internally, the array is wrapped by a QBuffer.
Definition at line 1077 of file qtextstream.cpp.
|
explicit |
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:
Definition at line 1104 of file qtextstream.cpp.
|
virtual |
Destroys the QTextStream.
If the stream operates on a device, flush() will be called implicitly. Otherwise, the device is unaffected.
Definition at line 1160 of file qtextstream.cpp.
Referenced by lowercasebase(), lowercasedigits(), noforcepoint(), noforcesign(), and noshowbase().
bool QTextStream::atEnd | ( | ) | 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.
Definition at line 1646 of file qtextstream.cpp.
Referenced by QMacPasteboardMimeVCard::convertFromMime(), getLocations(), QGtkStylePrivate::getThemeName(), getVariables(), launchWebBrowser(), qt_parseQconfig(), readConf(), readSourceFile(), and trimmed().
bool QTextStream::autoDetectUnicode | ( | ) | const |
Returns true if automatic Unicode detection is enabled, otherwise returns false.
Automatic Unicode detection is enabled by default.
Definition at line 3215 of file qtextstream.cpp.
QTextCodec * QTextStream::codec | ( | ) | const |
Returns the codec that is current assigned to the stream.
Definition at line 3186 of file qtextstream.cpp.
Referenced by encodeText(), QDomDocumentPrivate::saveDocument(), and setCodec().
QIODevice * QTextStream::device | ( | ) | const |
Returns the current device associated with the QTextStream, or 0 if no device has been assigned.
Definition at line 1352 of file qtextstream.cpp.
Referenced by QTextStream(), and setDevice().
QTextStream::FieldAlignment QTextStream::fieldAlignment | ( | ) | const |
Returns the current field alignment.
Definition at line 1415 of file qtextstream.cpp.
int QTextStream::fieldWidth | ( | ) | const |
Returns the current field width.
Definition at line 1476 of file qtextstream.cpp.
void QTextStream::flush | ( | ) |
Flushes any buffered data waiting to be written to the device.
If QTextStream operates on a string, this function does nothing.
Definition at line 1193 of file qtextstream.cpp.
Referenced by QMacPasteboardMimeVCard::convertFromMime(), endl(), flush(), QDeviceClosedNotifier::flushStream(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::outputGraph(), setDevice(), and setString().
bool QTextStream::generateByteOrderMark | ( | ) | 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.
Definition at line 3247 of file qtextstream.cpp.
int QTextStream::integerBase | ( | ) | const |
Returns the current base of integers.
0 means that the base is detected when reading, or 10 (decimal) when generating numbers.
Definition at line 1529 of file qtextstream.cpp.
Referenced by QTextStreamPrivate::getNumber(), and QTextStreamPrivate::putNumber().
QLocale QTextStream::locale | ( | ) | const |
Returns the locale for this stream.
The default locale is C.
Definition at line 3285 of file qtextstream.cpp.
Referenced by QTextStreamPrivate::getNumber(), QTextStreamPrivate::getReal(), QTextStreamPrivate::putNumber(), and setLocale().
QTextStream::NumberFlags QTextStream::numberFlags | ( | ) | const |
Returns the current number flags.
Definition at line 1501 of file qtextstream.cpp.
Referenced by forcepoint(), forcesign(), locale(), lowercasebase(), lowercasedigits(), noforcepoint(), noforcesign(), noshowbase(), operator<<(), QTextStreamPrivate::putNumber(), showbase(), uppercasebase(), and uppercasedigits().
QTextStream & QTextStream::operator<< | ( | QBool | b | ) |
Definition at line 2388 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | QChar | c | ) |
Writes the character c to the stream, then returns a reference to the QTextStream.
Definition at line 2399 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | char | c | ) |
Converts c from ASCII to a QChar, then writes it to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2415 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | signed short | i | ) |
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().
Definition at line 2431 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | unsigned short | i | ) |
Writes the unsigned short i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2447 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | signed int | i | ) |
Writes the signed int i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2463 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | unsigned int | i | ) |
Writes the unsigned int i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2479 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | signed long | i | ) |
Writes the signed long i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2495 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | unsigned long | i | ) |
Writes the unsigned long i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2511 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | qlonglong | i | ) |
Writes the qlonglong i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2527 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | qulonglong | i | ) |
Writes the qulonglong i to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2543 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | float | f | ) |
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().
Definition at line 2562 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | double | f | ) |
Writes the double f to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2575 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | 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.
Definition at line 2619 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | const QByteArray & | array | ) |
Writes array to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The contents of array are converted with QString::fromAscii().
Definition at line 2636 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | const char * | string | ) |
Writes the constant string pointed to by string to the stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
string is assumed to be in ISO-8859-1 encoding. This operator is convenient when working with constant string data. Example:
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.
Definition at line 2660 of file qtextstream.cpp.
QTextStream & QTextStream::operator<< | ( | const void * | ptr | ) |
Writes ptr to the stream as a hexadecimal number with a base.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2677 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | 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:
Whitespace is not skipped.
Definition at line 2061 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | char & | c | ) |
Reads a character from the stream and stores it in c.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The character from the stream is converted to ISO-5589-1 before it is stored.
Definition at line 2083 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | 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:
Prefix | Base |
"0b" or "0B" | 2 (binary) |
"0" followed by "0-7" | 8 (octal) |
"0" otherwise | 10 (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.
Definition at line 2115 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | unsigned short & | i | ) |
Stores the integer in the unsigned short i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2128 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | signed int & | i | ) |
Stores the integer in the signed int i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2141 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | unsigned int & | i | ) |
Stores the integer in the unsigned int i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2154 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | signed long & | i | ) |
Stores the integer in the signed long i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2167 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | unsigned long & | i | ) |
Stores the integer in the unsigned long i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2180 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | qlonglong & | i | ) |
Stores the integer in the qlonglong i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2193 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | qulonglong & | i | ) |
Stores the integer in the qulonglong i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2206 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | 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.
Definition at line 2222 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | double & | f | ) |
Stores the real number in the double f.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2235 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | 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.
Definition at line 2247 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | QByteArray & | array | ) |
Converts the word to ISO-8859-1, then stores it in array.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2278 of file qtextstream.cpp.
QTextStream & QTextStream::operator>> | ( | char * | c | ) |
Stores the word in c, terminated by a '\0' character.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.
Definition at line 2317 of file qtextstream.cpp.
QChar QTextStream::padChar | ( | ) | const |
Returns the current pad character.
Definition at line 1447 of file qtextstream.cpp.
qint64 QTextStream::pos | ( | ) | 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.
Definition at line 1251 of file qtextstream.cpp.
Referenced by setCodec().
Reads at most maxlen characters from the stream, and returns the data read as a QString.
Definition at line 1718 of file qtextstream.cpp.
QString QTextStream::readAll | ( | ) |
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.
Definition at line 1666 of file qtextstream.cpp.
Referenced by QScriptEngine::importExtension(), QCss::Parser::init(), QScriptDebuggerConsolePrivate::loadScriptedCommands(), operator<<(), and QDeclarativeScriptParser::parse().
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().
Definition at line 1692 of file qtextstream.cpp.
Referenced by QMacPasteboardMimeVCard::convertFromMime(), getLocations(), QGtkStylePrivate::getThemeName(), getVariables(), launchWebBrowser(), QSplitter::operator>>(), QDeclarativeDirParser::parse(), qt_parseQconfig(), readConf(), readSourceFile(), and trimmed().
QTextStream::RealNumberNotation QTextStream::realNumberNotation | ( | ) | const |
Returns the current real number notation.
Definition at line 1554 of file qtextstream.cpp.
Referenced by operator<<().
int QTextStream::realNumberPrecision | ( | ) | const |
Returns the current real number precision, or the number of fraction digits QTextStream will write when generating real numbers.
Definition at line 1586 of file qtextstream.cpp.
void QTextStream::reset | ( | ) |
Resets QTextStream's formatting options, bringing it back to its original constructed state.
The device, string and any buffered data is left untouched.
Definition at line 1175 of file qtextstream.cpp.
Referenced by reset().
void QTextStream::resetStatus | ( | ) |
Resets the status of the text stream.
Definition at line 1614 of file qtextstream.cpp.
bool QTextStream::seek | ( | qint64 | pos | ) |
Seeks to the position pos in the device.
Returns true on success; otherwise returns false.
Definition at line 1203 of file qtextstream.cpp.
Referenced by setCodec().
void QTextStream::setAutoDetectUnicode | ( | 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.
Definition at line 3203 of file qtextstream.cpp.
void QTextStream::setCodec | ( | 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.
Definition at line 3148 of file qtextstream.cpp.
Referenced by locale(), operator<<(), QDeclarativeScriptParser::parse(), QDomDocumentPrivate::saveDocument(), setCodec(), and QTextDocumentWriter::write().
void QTextStream::setCodec | ( | 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:
Definition at line 3174 of file qtextstream.cpp.
void QTextStream::setDevice | ( | 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.
Definition at line 1325 of file qtextstream.cpp.
Referenced by DumpIDL().
void QTextStream::setFieldAlignment | ( | 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.
Definition at line 1404 of file qtextstream.cpp.
Referenced by center(), left(), locale(), and right().
void QTextStream::setFieldWidth | ( | 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.
Definition at line 1465 of file qtextstream.cpp.
Referenced by qSetFieldWidth().
void QTextStream::setGenerateByteOrderMark | ( | 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.
Definition at line 3229 of file qtextstream.cpp.
Referenced by bom().
void QTextStream::setIntegerBase | ( | 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.
Definition at line 1517 of file qtextstream.cpp.
Referenced by bin(), dec(), hex(), locale(), and oct().
void QTextStream::setLocale | ( | 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.
Definition at line 3269 of file qtextstream.cpp.
void QTextStream::setNumberFlags | ( | 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).
Definition at line 1490 of file qtextstream.cpp.
Referenced by forcepoint(), forcesign(), locale(), lowercasebase(), lowercasedigits(), noforcepoint(), noforcesign(), noshowbase(), showbase(), uppercasebase(), and uppercasedigits().
void QTextStream::setPadChar | ( | 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:
The string s
contains:
Definition at line 1436 of file qtextstream.cpp.
Referenced by qSetPadChar().
void QTextStream::setRealNumberNotation | ( | 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.
Definition at line 1543 of file qtextstream.cpp.
Referenced by fixed(), locale(), and scientific().
void QTextStream::setRealNumberPrecision | ( | 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.
Definition at line 1569 of file qtextstream.cpp.
Referenced by qSetRealNumberPrecision().
void QTextStream::setStatus | ( | Status | status | ) |
Sets the status of the text stream to the status given.
Subsequent calls to setStatus() are ignored until resetStatus() is called.
Definition at line 1633 of file qtextstream.cpp.
Referenced by operator>>().
void QTextStream::setString | ( | 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.
Definition at line 1365 of file qtextstream.cpp.
void QTextStream::skipWhiteSpace | ( | ) |
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.
Definition at line 1307 of file qtextstream.cpp.
Referenced by ws().
QTextStream::Status QTextStream::status | ( | ) | const |
Returns the status of the text stream.
Definition at line 1598 of file qtextstream.cpp.
Referenced by QWSCalibratedMouseHandler::readCalibration(), setStatus(), and write_xpm_image().
QString * QTextStream::string | ( | ) | const |
Returns the current string assigned to the QTextStream, or 0 if no string has been assigned.
Definition at line 1390 of file qtextstream.cpp.
Referenced by QTextStream(), seek(), and setString().
|
related |
Calls QTextStream::setIntegerBase(2) on stream and returns stream.
Definition at line 2702 of file qtextstream.cpp.
Referenced by locale().
|
related |
Toggles insertion of the Byte Order Mark on stream when QTextStream is used with a UTF codec.
Definition at line 3127 of file qtextstream.cpp.
|
related |
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.
Definition at line 3009 of file qtextstream.cpp.
Referenced by QTriangulator< T >::ComplexToSimple::Event::operator<(), QRect::QRect(), and QSplashScreen::setPixmap().
|
related |
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
Definition at line 2736 of file qtextstream.cpp.
Referenced by locale().
|
related |
Writes '
' to the stream and flushes the stream.
Equivalent to
Note: On Windows, all '
' characters are written as '
' if QTextStream's device or string is opened using the QIODevice::Text flag.
Definition at line 3032 of file qtextstream.cpp.
Referenced by classIDL(), DumpIDL(), noegl(), and qax_generateDocumentation().
|
related |
Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream.
Definition at line 2941 of file qtextstream.cpp.
Referenced by addFontToDatabase(), and locale().
|
related |
Calls QTextStream::flush() on stream and returns stream.
Definition at line 3047 of file qtextstream.cpp.
Referenced by QDirectFBWindowSurface::paintDevice().
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForcePoint) on stream and returns stream.
Definition at line 2805 of file qtextstream.cpp.
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and returns stream.
Definition at line 2788 of file qtextstream.cpp.
|
related |
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
Definition at line 2754 of file qtextstream.cpp.
Referenced by initWritingSystems(), locale(), and verifyTag().
|
related |
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream.
Definition at line 2975 of file qtextstream.cpp.
Referenced by locale(), QRect::QRect(), and QWindowsMobileStyle::subControlRect().
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseBase) on stream and returns stream.
Definition at line 2907 of file qtextstream.cpp.
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseDigits) on stream and returns stream.
Definition at line 2924 of file qtextstream.cpp.
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForcePoint) on stream and returns stream.
Definition at line 2856 of file qtextstream.cpp.
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and returns stream.
Definition at line 2839 of file qtextstream.cpp.
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and returns stream.
Definition at line 2822 of file qtextstream.cpp.
|
related |
Calls QTextStream::setIntegerBase(8) on stream and returns stream.
Definition at line 2719 of file qtextstream.cpp.
Referenced by locale().
|
related |
Equivalent to QTextStream::setFieldWidth(width).
Definition at line 329 of file qtextstream.h.
|
related |
Equivalent to QTextStream::setPadChar(ch).
Definition at line 335 of file qtextstream.h.
|
related |
Equivalent to QTextStream::setRealNumberPrecision(precision).
Definition at line 341 of file qtextstream.h.
|
related |
Calls QTextStream::reset() on stream and returns stream.
Definition at line 3063 of file qtextstream.cpp.
|
related |
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream.
Definition at line 2992 of file qtextstream.cpp.
Referenced by QPainterPath::computeBoundingRect(), locale(), and QRect::QRect().
|
related |
Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) on stream and returns stream.
Definition at line 2958 of file qtextstream.cpp.
Referenced by locale().
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and returns stream.
Definition at line 2771 of file qtextstream.cpp.
Referenced by locale().
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseBase) on stream and returns stream.
Definition at line 2873 of file qtextstream.cpp.
|
related |
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseDigits) on stream and returns stream.
Definition at line 2890 of file qtextstream.cpp.
|
related |
Calls skipWhiteSpace() on stream and returns stream.
Definition at line 3079 of file qtextstream.cpp.
|
private |
Definition at line 261 of file qtextstream.h.