Q3TextStream Class ReferenceThe Q3TextStream class provides basic functions for reading and writing text using a QIODevice. More... #include <Q3TextStream> This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information. Note: All functions in this class are reentrant. Public Types
Public Functions
Detailed DescriptionThe Q3TextStream 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 Q3TextStream 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 Q3TextStream 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 Q3TextStream 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. Member Type Documentationenum Q3TextStream::Encoding
See setEncoding() for an explanation of the encodings. Member Function DocumentationQ3TextStream::Q3TextStream ()Constructs a data stream that has no IO device. Q3TextStream::Q3TextStream ( QIODevice * iod )Constructs a text stream that uses the IO device iod. Q3TextStream::Q3TextStream ( QString * str, int filemode )Constructs a text stream that operates on the Unicode QString, str, through an internal device. The filemode argument is passed to the device's open() function; see QIODevice::mode(). If you set an encoding or codec with setEncoding() or setCodec(), this setting is ignored for text streams that operate on QString. Example: QString str;
Q3TextStream ts( &str, IO_WriteOnly );
ts << "pi = " << 3.14; // str == "pi = 3.14"
Writing data to the text stream will modify the contents of the string. The string will be expanded when data is written beyond the end of the string. Note that the string will not be truncated: QString str = "pi = 3.14";
Q3TextStream ts( &str, IO_WriteOnly );
ts << "2+2 = " << 2+2; // str == "2+2 = 414"
Note that because QString is Unicode, you should not use readRawBytes() or writeRawBytes() on such a stream. Q3TextStream::Q3TextStream ( QByteArray & a, int mode )Constructs a text stream that operates on the byte array, a, through an internal QBuffer device. The mode argument is passed to the device's open() function; see QIODevice::mode(). Example: QByteArray array;
Q3TextStream ts( array, IO_WriteOnly );
ts << "pi = " << 3.14 << '\0'; // array == "pi = 3.14"
Writing data to the text stream will modify the contents of the array. The array will be expanded when data is written beyond the end of the string. Same example, using a QBuffer: QByteArray array;
QBuffer buf( array );
buf.open( IO_WriteOnly );
Q3TextStream ts( &buf );
ts << "pi = " << 3.14 << '\0'; // array == "pi = 3.14"
buf.close();
Q3TextStream::Q3TextStream ( FILE * fh, int mode )Constructs a text stream that operates on an existing file handle fh through an internal QFile device. The mode argument is passed to the device's open() function; see QIODevice::mode(). Note that if you create a Q3TextStream cout or another name that is also used for another variable of a different type, some linkers may confuse the two variables, which will often cause crashes. Q3TextStream::~Q3TextStream () [virtual]Destroys the text stream. The destructor does not affect the current IO device. bool Q3TextStream::atEnd () constReturns TRUE if the IO device has reached the end position (end of the stream or file) or if there is no IO device set; otherwise returns FALSE. This function was introduced in Qt 4.2. See also QIODevice::atEnd(). QTextCodec * Q3TextStream::codec ()Returns the codec actually used for this stream. If Unicode is automatically detected in input, a codec with name() "ISO-10646-UCS-2" is returned. This function was introduced in Qt 4.2. See also setCodec(). QIODevice * Q3TextStream::device () constReturns the IO device currently set. This function was introduced in Qt 4.2. See also setDevice() and unsetDevice(). int Q3TextStream::fill () constReturns the fill character. The default value is ' ' (space). This function was introduced in Qt 4.2. int Q3TextStream::fill ( int f )This is an overloaded function. Sets the fill character to f. Returns the previous fill character. int Q3TextStream::flags () constReturns the current stream flags. The default value is 0.
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 function was introduced in Qt 4.2. int Q3TextStream::flags ( int f )This is an overloaded function. Sets the stream flags to f. Returns the previous stream flags. See also setf(), unsetf(), and flags(). int Q3TextStream::precision () constReturns the precision. The default value is 6. This function was introduced in Qt 4.2. int Q3TextStream::precision ( int p )This is an overloaded function. Sets the precision to p. Returns the previous precision setting. QString Q3TextStream::read ()Reads the entire stream from the current position, and returns a string containing the text. This function was introduced in Qt 4.2. See also readLine(). QString Q3TextStream::readLine ()Reads a line from the stream and returns a string containing the text. 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. This function was introduced in Qt 4.2. See also QIODevice::readLine(). Q3TextStream & Q3TextStream::readRawBytes ( char * s, uint len )Reads len bytes from the stream into s and returns a reference to the stream. 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. This function was introduced in Qt 4.2. See also QIODevice::readBlock(). void Q3TextStream::reset ()Resets the text stream.
This function was introduced in Qt 4.2. See also setf(), width(), fill(), and precision(). void Q3TextStream::setCodec ( QTextCodec * codec )Sets the codec for this stream to codec. Will not try to autodetect Unicode. Note that this function should be called before any data is read to/written from the stream. This function was introduced in Qt 4.2. See also setEncoding() and codec(). void Q3TextStream::setDevice ( QIODevice * iod )Sets the IO device to iod. This function was introduced in Qt 4.2. See also device() and unsetDevice(). void Q3TextStream::setEncoding ( Encoding e )Sets the encoding of this stream to e, where e is one of the following values:
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. This function was introduced in Qt 4.2. See also setCodec(). int Q3TextStream::setf ( int bits )Sets the stream flag bits bits. Returns the previous stream flags. Equivalent to flags( flags() | bits ). This function was introduced in Qt 4.2. See also unsetf(). int Q3TextStream::setf ( int bits, int mask )This is an overloaded function. Sets the stream flag bits bits with a bit mask mask. Returns the previous stream flags. Equivalent to flags( (flags() & ~mask) | (bits & mask) ). void Q3TextStream::skipWhiteSpace ()Positions the read pointer at the first non-whitespace character. This function was introduced in Qt 4.2. void Q3TextStream::unsetDevice ()Unsets the IO device. Equivalent to setDevice( 0 ). This function was introduced in Qt 4.2. See also device() and setDevice(). int Q3TextStream::unsetf ( int bits )Clears the stream flag bits bits. Returns the previous stream flags. Equivalent to flags( flags() & ~mask ). This function was introduced in Qt 4.2. See also setf(). int Q3TextStream::width () constReturns the field width. The default value is 0. This function was introduced in Qt 4.2. int Q3TextStream::width ( int w )This is an overloaded function. Sets the field width to w. Returns the previous field width. Q3TextStream & Q3TextStream::writeRawBytes ( const char * s, uint len )Writes the len bytes from s to the stream and returns a reference to the stream. Note that no encoding is done by this function. This function was introduced in Qt 4.2. See also QIODevice::writeBlock(). Q3TextStream & Q3TextStream::operator<< ( QChar c )Writes character char to the stream and returns a reference to the stream. The character c is assumed to be Latin1 encoded independent of the Encoding set for the Q3TextStream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( char c )This is an overloaded function. Writes character c to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( signed short i )This is an overloaded function. Writes a short integer i to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( unsigned short i )This is an overloaded function. Writes an unsigned short integer i to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( signed int i )This is an overloaded function. Writes an int i to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( unsigned int i )This is an overloaded function. Writes an unsigned int i to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( signed long i )This is an overloaded function. Writes a long int i to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( unsigned long i )This is an overloaded function. Writes an unsigned long int i to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( float f )This is an overloaded function. Writes a float f to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( double f )This is an overloaded function. Writes a double f to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( const char * s )This is an overloaded function. 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 Q3TextStream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( const Q3CString & s )This is an overloaded function. 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 Q3TextStream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( const QString & s )This is an overloaded function. Writes s to the stream and returns a reference to the stream. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator<< ( void * ptr )This is an overloaded function. Writes a pointer to the stream and returns a reference to the stream. The ptr is output as an unsigned long hexadecimal integer. This function was introduced in Qt 4.2. Q3TextStream & Q3TextStream::operator>> ( QChar & c )Reads a char c from the stream and returns a reference to the stream. Note that whitespace is not skipped. Q3TextStream & Q3TextStream::operator>> ( char & c )This is an overloaded function. Reads a char c from the stream and returns a reference to the stream. Note that whitespace is skipped. Q3TextStream & Q3TextStream::operator>> ( signed short & i )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( unsigned short & i )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( signed int & i )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( unsigned int & i )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( signed long & i )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( unsigned long & i )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( float & f )This is an overloaded function. Reads a float f from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format. Q3TextStream & Q3TextStream::operator>> ( double & f )This is an overloaded function. Reads a double f from the stream and returns a reference to the stream. See flags() for an explanation of the expected input format. Q3TextStream & Q3TextStream::operator>> ( char * s )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( QString & str )This is an overloaded function. 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. Q3TextStream & Q3TextStream::operator>> ( Q3CString & str )This is an overloaded function. 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. X
|
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |