QTextStream Class ReferenceThe QTextStream class provides basic functions for reading and writing text using a QIODevice. More... All the functions in this class are reentrant when Qt is built with thread support. #include <qtextstream.h> Inherited by QTextIStream and QTextOStream. Public Members
Detailed DescriptionThe QTextStream class provides basic functions for reading and writing text using a QIODevice.
The text stream class has a functional interface that is very similar to that of the standard C++ iostream class. Qt provides several global functions similar to the ones in iostream:
Warning: By default QTextStream will automatically detect whether integers in the stream are in decimal, octal, hexadecimal or binary format when reading from the stream. In particular, a leading '0' signifies octal, i.e. the sequence "0100" will be interpreted as 64. The QTextStream class reads and writes text; it is not appropriate for dealing with binary data (but QDataStream is). By default, output of Unicode text (i.e. QString) is done using the local 8-bit encoding. This can be changed using the setEncoding() method. For input, the QTextStream will auto-detect standard Unicode "byte order marked" text files; otherwise the local 8-bit encoding is used. The QIODevice is set in the constructor, or later using setDevice(). If the end of the input is reached atEnd() returns TRUE. Data can be read into variables of the appropriate type using the operator>>() overloads, or read in its entirety into a single string using read(), or read a line at a time using readLine(). Whitespace can be skipped over using skipWhiteSpace(). You can set flags for the stream using flags() or setf(). The stream also supports width(), precision() and fill(); use reset() to reset the defaults.
See also QDataStream, Input/Output and Networking, and Text Related Classes. Member Type Documentation
|
Flag | Meaning |
---|---|
skipws | Not currently used; whitespace always skipped |
left | Numeric fields are left-aligned |
right | Not currently used (by default, numerics are right-aligned) |
internal | Puts any padding spaces between +/- and value |
bin | Output and input only in binary |
oct | Output and input only in octal |
dec | Output and input only in decimal |
hex | Output and input only in hexadecimal |
showbase | Annotates numeric outputs with 0b, 0, or 0x if in bin, oct, or hex format |
showpoint | Not currently used |
uppercase | Uses 0B and 0X rather than 0b and 0x |
showpos | Shows + for positive numeric values |
scientific | Uses scientific notation for floating point values |
fixed | Uses fixed-point notation for floating point values |
Note that unless bin, oct, dec, or hex is set, the input base is octal if the value starts with 0, hexadecimal if it starts with 0x, binary if it starts with 0b, and decimal otherwise.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the stream flags to f. Returns the previous stream flags.
The character c is assumed to be Latin1 encoded independent of the Encoding set for the QTextStream.
Writes character c to the stream and returns a reference to the stream.
Writes a short integer i to the stream and returns a reference to the stream.
Writes an unsigned short integer i to the stream and returns a reference to the stream.
Writes an int i to the stream and returns a reference to the stream.
Writes an unsigned int i to the stream and returns a reference to the stream.
Writes a long int i to the stream and returns a reference to the stream.
Writes an unsigned long int i to the stream and returns a reference to the stream.
Writes a float f to the stream and returns a reference to the stream.
Writes a double f to the stream and returns a reference to the stream.
Writes a string to the stream and returns a reference to the stream.
The string s is assumed to be Latin1 encoded independent of the Encoding set for the QTextStream.
Writes s to the stream and returns a reference to the stream.
Writes s to the stream and returns a reference to the stream.
The string s is assumed to be Latin1 encoded independent of the Encoding set for the QTextStream.
Writes a pointer to the stream and returns a reference to the stream.
The ptr is output as an unsigned long hexadecimal integer.
Reads a char c from the stream and returns a reference to the stream. Note that whitespace is skipped.
Reads a signed short integer i from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads an unsigned short integer i from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads a signed int i from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads an unsigned int i from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads a signed long int i from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads an unsigned long int i from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads a float f from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads a double f from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format.
Reads a "word" from the stream into s and returns a reference to the stream.
A word consists of characters for which isspace() returns FALSE.
Reads a "word" from the stream into str and returns a reference to the stream.
A word consists of characters for which isspace() returns FALSE.
Reads a "word" from the stream into str and returns a reference to the stream.
A word consists of characters for which isspace() returns FALSE.
Returns the precision. The default value is 6.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the precision to p. Returns the previous precision setting.
See also QIODevice::readLine().
Examples: action/application.cpp, application/application.cpp, mdi/application.cpp, qdir/qdir.cpp, and qwerty/qwerty.cpp.
The returned string does not contain any trailing newline or carriage return. Note that this is different from QIODevice::readLine(), which does not strip the newline at the end of the line.
On EOF you will get a QString that is null. On reading an empty line the returned QString is empty but not null.
See also QIODevice::readLine().
Examples: addressbook/centralwidget.cpp, chart/element.cpp, and network/clientserver/server/server.cpp.
The buffer s must be preallocated.
Note that no encoding is done by this function.
Warning: The behavior of this function is undefined unless the stream's encoding is set to Unicode or Latin1.
See also QIODevice::readBlock().
See also setf(), width(), fill(), and precision().
Note that this function should be called before any data is read to/written from the stream.
See also setEncoding() and codec().
Example: qwerty/qwerty.cpp.
See also device() and unsetDevice().
Encoding | Meaning |
---|---|
Locale | Uses local file format (Latin1 if locale is not set), but autodetecting Unicode(utf16) on input. |
Unicode | Uses Unicode(utf16) for input and output. Output will be written in the order most efficient for the current platform (i.e. the order used internally in QString). |
UnicodeUTF8 | Using Unicode(utf8) for input and output. If you use it for input it will autodetect utf16 and use it instead of utf8. |
Latin1 | ISO-8859-1. Will not autodetect utf16. |
UnicodeNetworkOrder | Uses network order Unicode(utf16) for input and output. Useful when reading Unicode data that does not start with the byte order marker. |
UnicodeReverse | Uses reverse network order Unicode(utf16) for input and output. Useful when reading Unicode data that does not start with the byte order marker or when writing data that should be read by buggy Windows applications. |
RawUnicode | Like Unicode, but does not write the byte order marker nor does it auto-detect the byte order. Useful only when writing to non-persistent storage used by a single process. |
Locale and all Unicode encodings, except RawUnicode, will look at the first two bytes in an input stream to determine the byte order. The initial byte order marker will be stripped off before data is read.
Note that this function should be called before any data is read to or written from the stream.
See also setCodec().
Examples: network/httpd/httpd.cpp and qwerty/qwerty.cpp.
Sets the stream flag bits bits. Returns the previous stream flags.
Equivalent to flags( flags() | bits ).
See also unsetf().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the stream flag bits bits with a bit mask mask. Returns the previous stream flags.
Equivalent to flags( (flags() & ~mask) | (bits & mask) ).
See also unsetf().
See also device() and setDevice().
Clears the stream flag bits bits. Returns the previous stream flags.
Equivalent to flags( flags() & ~mask ).
See also setf().
Returns the field width. The default value is 0.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the field width to w. Returns the previous field width.
Note that no encoding is done by this function.
See also QIODevice::writeBlock().
This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.2 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com