QTextStream Class Reference
|
Manipulator | Описание |
---|---|
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<<('\n') 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().
See also QDataStream, QIODevice, QFile, QBuffer, QTcpSocket, and Codecs Example.
This enum specifies how to align text in fields when the field is wider than the text that occupies it.
Константа | Значение | Описание |
---|---|---|
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().
This enum specifies various flags that can be set to affect the output of integers, floats, and doubles.
Константа | Значение | Описание |
---|---|---|
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. |
The NumberFlags type is a typedef for QFlags<NumberFlag>. It stores an OR combination of NumberFlag values.
See also setNumberFlags().
This enum specifies which notations to use for expressing float and double as strings.
Константа | Значение | Описание |
---|---|---|
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().
This enum describes the current status of the text stream.
Константа | Значение | Описание |
---|---|---|
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().
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().
Constructs a QTextStream that operates on device.
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. Пример:
QString str; QTextStream in(stdin); in >> str;
Constructs a QTextStream that operates on string, using openMode to define the open mode.
Constructs a QTextStream that operates on array, using openMode to define the open mode. Internally, the array is wrapped by a QBuffer.
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. Пример:
int main(int argc, char *argv[])
{
// read numeric arguments (123, 0x20, 4.5...)
for (int i = 1; i < argc; ++i) {
int number;
QTextStream in(argv[i]);
in >> number;
...
}
}
Destroys the QTextStream.
If the stream operates on a device, flush() will be called implicitly. Otherwise, the device is unaffected.
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.
Returns true if automatic Unicode detection is enabled; otherwise returns false.
See also setAutoDetectUnicode() and setCodec().
Returns the codec that is current assigned to the stream.
See also setCodec(), setAutoDetectUnicode(), and locale().
Returns the current device associated with the QTextStream, or 0 if no device has been assigned.
See also setDevice() and string().
Returns the current field alignment.
See also setFieldAlignment() and fieldWidth().
Returns the current field width.
See also setFieldWidth().
Flushes any buffered data waiting to be written to the device.
If QTextStream operates on a string, this function does nothing.
Returns true if QTextStream is set to generate the UTF BOM (Byte Order Mark) when using a UTF codec; otherwise returns false.
See also setGenerateByteOrderMark().
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().
Returns the locale for this stream. The default locale is C.
Эта функция была введена в Qt 4.5.
See also setLocale().
Returns the current number flags.
See also setNumberFlags(), integerBase(), and realNumberNotation().
Returns the current pad character.
See also setPadChar() and setFieldWidth().
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.
Эта функция была введена в Qt 4.2.
See also seek().
Reads at most maxlen characters from the stream, and returns the data read as a QString.
Эта функция была введена в Qt 4.1.
See also readAll(), readLine(), and QIODevice::read().
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.
Смотрите также readLine().
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().
Returns the current real number notation.
See also setRealNumberNotation(), realNumberPrecision(), numberFlags(), and integerBase().
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().
Resets QTextStream's formatting options, bringing it back to its original constructed state. The device, string and any buffered data is left untouched.
Resets the status of the text stream.
Эта функция была введена в Qt 4.1.
See also QTextStream::Status, status(), and setStatus().
Seeks to the position pos in the device. Возвращает true, если всё прошло успешно; в противном случае возвращает false.
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().
Устанавливает кодет для текущего потока в 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().
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.
Пример:
QTextStream out(&file); out.setCodec("UTF-8");
See also QTextCodec::codecForName() and setLocale().
Устанавливает текущее устройство в 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().
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().
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().
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().
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().
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.
Эта функция была введена в Qt 4.5.
See also locale().
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().
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.
Пример:
QString s; QTextStream out(&s); out.setFieldWidth(10); out.setFieldAlignment(QTextStream::AlignCenter); out.setPadChar('-'); out << "Qt" << "rocks!";
The string s contains:
----Qt------rocks!--
See also padChar() and setFieldWidth().
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().
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().
Sets the status of the text stream to the status given.
Эта функция была введена в Qt 4.1.
See also Status, status(), and resetStatus().
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().
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>>().
Returns the status of the text stream.
See also QTextStream::Status, setStatus(), and resetStatus().
Returns the current string assigned to the QTextStream, or 0 if no string has been assigned.
See also setString() and device().
Writes the character c to the stream, then returns a reference to the QTextStream.
See also setFieldWidth().
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().
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().
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().
Это перегруженная функция.
Converts c from ASCII to a QChar, then writes it to the stream.
Это перегруженная функция.
Writes the unsigned short i to the stream.
Это перегруженная функция.
Writes the signed int i to the stream.
Это перегруженная функция.
Writes the unsigned int i to the stream.
Это перегруженная функция.
Writes the signed long i to the stream.
Это перегруженная функция.
Writes the unsigned long i to the stream.
Это перегруженная функция.
Writes the qlonglong i to the stream.
Это перегруженная функция.
Writes the qulonglong i to the stream.
Это перегруженная функция.
Writes the double f to the stream.
Это перегруженная функция.
Writes array to the stream. The contents of array are converted with QString::fromAscii().
Это перегруженная функция.
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. Пример:
QTextStream out(stdout); 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.
Это перегруженная функция.
Writes ptr to the stream as a hexadecimal number with a base.
Reads a character from the stream and stores it in c. Returns a reference to the QTextStream, so several operators can be nested. Пример:
QTextStream in(file); QChar ch1, ch2, ch3; in >> ch1 >> ch2 >> ch3;
Whitespace is not skipped.
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:
Префикс | 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.
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.
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.
Это перегруженная функция.
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().
Это перегруженная функция.
Stores the integer in the unsigned short i.
Это перегруженная функция.
Stores the integer in the signed int i.
Это перегруженная функция.
Stores the integer in the unsigned int i.
Это перегруженная функция.
Stores the integer in the signed long i.
Это перегруженная функция.
Stores the integer in the unsigned long i.
Это перегруженная функция.
Stores the integer in the qlonglong i.
Это перегруженная функция.
Stores the integer in the qulonglong i.
Это перегруженная функция.
Stores the real number in the double f.
Это перегруженная функция.
Converts the word to ISO-8859-1, then stores it in array.
See also QString::toLatin1().
Это перегруженная функция.
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.
Calls QTextStream::setIntegerBase(2) on stream and returns stream.
See also oct(), dec(), hex(), and QTextStream manipulators.
Toggles insertion of the Byte Order Mark on stream when QTextStream is used with a UTF codec.
See also QTextStream::setGenerateByteOrderMark() and QTextStream manipulators.
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.
See also left(), right(), and QTextStream manipulators.
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
See also bin(), oct(), hex(), and QTextStream manipulators.
Writes '\n' to the stream and flushes the stream.
Equivalent to
stream << '\n' << flush;
Note: On Windows, all '\n' characters are written as '\r\n' if QTextStream's device or string is opened using the QIODevice::Text flag.
See also flush(), reset(), and QTextStream manipulators.
Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream.
See also scientific() and QTextStream manipulators.
Calls QTextStream::flush() on stream and returns stream.
See also endl(), reset(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForcePoint) on stream and returns stream.
See also noforcepoint(), forcesign(), showbase(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and returns stream.
See also noforcesign(), forcepoint(), showbase(), and QTextStream manipulators.
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
Note: The hex modifier can only be used for writing to streams.
See also bin(), oct(), dec(), and QTextStream manipulators.
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream.
See also right(), center(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseBase) on stream and returns stream.
See also uppercasebase(), lowercasedigits(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseDigits) on stream and returns stream.
See also uppercasedigits(), lowercasebase(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForcePoint) on stream and returns stream.
See also forcepoint(), noforcesign(), noshowbase(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and returns stream.
See also forcesign(), noforcepoint(), noshowbase(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and returns stream.
See also showbase(), noforcesign(), noforcepoint(), and QTextStream manipulators.
Calls QTextStream::setIntegerBase(8) on stream and returns stream.
See also bin(), dec(), hex(), and QTextStream manipulators.
Equivalent to QTextStream::setFieldWidth(width).
Equivalent to QTextStream::setPadChar(ch).
Equivalent to QTextStream::setRealNumberPrecision(precision).
Calls QTextStream::reset() on stream and returns stream.
See also flush() and QTextStream manipulators.
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream.
See also left(), center(), and QTextStream manipulators.
Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) on stream and returns stream.
See also fixed() and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and returns stream.
See also noshowbase(), forcesign(), forcepoint(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseBase) on stream and returns stream.
See also lowercasebase(), uppercasedigits(), and QTextStream manipulators.
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseDigits) on stream and returns stream.
See also lowercasedigits(), uppercasebase(), and QTextStream manipulators.
Calls skipWhiteSpace() on stream and returns stream.
See also QTextStream manipulators.
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Торговые марки | Qt 4.5.3 |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |