Struct qt_core::QTextStream

source ·
#[repr(C)]
pub struct QTextStream { /* private fields */ }
Expand description

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

C++ class: QTextStream.

C++ documentation:

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:

QFile data(“output.txt”); if (data.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream out(&data); out << “Result: “ << qSetFieldWidth(10) << left << 3.14 << 2.7; // writes “Result: 3.14 2.7 “ }

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:

QTextStream stream(stdin); QString line; while (stream.readLineInto(&line)) { ... }

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 in(“0x50 0x20”); int firstNumber, secondNumber;

in >> firstNumber; // firstNumber == 80 in >> dec >> secondNumber; // secondNumber == 0

char ch; in >> ch; // ch == ‘x’

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

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

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

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

Implementations§

source§

impl QTextStream

source

pub unsafe fn at_end(&self) -> bool

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.

Calls C++ function: bool QTextStream::atEnd() const.

C++ documentation:

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.

source

pub unsafe fn auto_detect_unicode(&self) -> bool

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

Calls C++ function: bool QTextStream::autoDetectUnicode() const.

C++ documentation:

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

See also setAutoDetectUnicode() and setCodec().

source

pub unsafe fn codec(&self) -> Ptr<QTextCodec>

Returns the codec that is current assigned to the stream.

Calls C++ function: QTextCodec* QTextStream::codec() const.

C++ documentation:

Returns the codec that is current assigned to the stream.

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

source

pub unsafe fn device(&self) -> QPtr<QIODevice>

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

Calls C++ function: QIODevice* QTextStream::device() const.

C++ documentation:

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

See also setDevice() and string().

source

pub unsafe fn field_alignment(&self) -> FieldAlignment

Returns the current field alignment.

Calls C++ function: QTextStream::FieldAlignment QTextStream::fieldAlignment() const.

C++ documentation:

Returns the current field alignment.

See also setFieldAlignment() and fieldWidth().

source

pub unsafe fn field_width(&self) -> c_int

Returns the current field width.

Calls C++ function: int QTextStream::fieldWidth() const.

C++ documentation:

Returns the current field width.

See also setFieldWidth().

source

pub unsafe fn flush(&self)

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

Calls C++ function: void QTextStream::flush().

C++ documentation:

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

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

source

pub unsafe fn generate_byte_order_mark(&self) -> bool

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.

Calls C++ function: bool QTextStream::generateByteOrderMark() const.

C++ documentation:

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

See also setGenerateByteOrderMark().

source

pub unsafe fn integer_base(&self) -> c_int

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

Calls C++ function: int QTextStream::integerBase() const.

C++ documentation:

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().

source

pub unsafe fn locale(&self) -> CppBox<QLocale>

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

Calls C++ function: QLocale QTextStream::locale() const.

C++ documentation:

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

This function was introduced in Qt 4.5.

See also setLocale().

source

pub unsafe fn new() -> CppBox<QTextStream>

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

Calls C++ function: [constructor] void QTextStream::QTextStream().

C++ documentation:

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().

source

pub unsafe fn from_q_io_device( device: impl CastInto<Ptr<QIODevice>> ) -> CppBox<QTextStream>

Constructs a QTextStream that operates on device.

Calls C++ function: [constructor] void QTextStream::QTextStream(QIODevice* device).

C++ documentation:

Constructs a QTextStream that operates on device.

source

pub unsafe fn from_q_string_q_flags_open_mode_flag( string: impl CastInto<Ptr<QString>>, open_mode: QFlags<OpenModeFlag> ) -> CppBox<QTextStream>

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

Calls C++ function: [constructor] void QTextStream::QTextStream(QString* string, QFlags<QIODevice::OpenModeFlag> openMode = …).

C++ documentation:

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

source

pub unsafe fn from_q_byte_array_q_flags_open_mode_flag( array: impl CastInto<Ptr<QByteArray>>, open_mode: QFlags<OpenModeFlag> ) -> CppBox<QTextStream>

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

Calls C++ function: [constructor] void QTextStream::QTextStream(QByteArray* array, QFlags<QIODevice::OpenModeFlag> openMode = …).

C++ documentation:

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

source

pub unsafe fn from_q_byte_array_q_flags_open_mode_flag2( array: impl CastInto<Ref<QByteArray>>, open_mode: QFlags<OpenModeFlag> ) -> CppBox<QTextStream>

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.

Calls C++ function: [constructor] void QTextStream::QTextStream(const QByteArray& array, QFlags<QIODevice::OpenModeFlag> openMode = …).

C++ documentation:

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:

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; ... } }

source

pub unsafe fn from_q_string( string: impl CastInto<Ptr<QString>> ) -> CppBox<QTextStream>

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

Calls C++ function: [constructor] void QTextStream::QTextStream(QString* string).

C++ documentation:

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

source

pub unsafe fn from_q_byte_array( array: impl CastInto<Ptr<QByteArray>> ) -> CppBox<QTextStream>

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

Calls C++ function: [constructor] void QTextStream::QTextStream(QByteArray* array).

C++ documentation:

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

source

pub unsafe fn from_q_byte_array2( array: impl CastInto<Ref<QByteArray>> ) -> CppBox<QTextStream>

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.

Calls C++ function: [constructor] void QTextStream::QTextStream(const QByteArray& array).

C++ documentation:

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:

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; ... } }

source

pub unsafe fn number_flags(&self) -> QFlags<NumberFlag>

Returns the current number flags.

Calls C++ function: QFlags<QTextStream::NumberFlag> QTextStream::numberFlags() const.

C++ documentation:

Returns the current number flags.

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

source

pub unsafe fn pad_char(&self) -> CppBox<QChar>

Returns the current pad character.

Calls C++ function: QChar QTextStream::padChar() const.

C++ documentation:

Returns the current pad character.

See also setPadChar() and setFieldWidth().

source

pub unsafe fn pos(&self) -> i64

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).

Calls C++ function: qint64 QTextStream::pos() const.

C++ documentation:

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.

This function was introduced in Qt 4.2.

See also seek().

source

pub unsafe fn read(&self, maxlen: i64) -> CppBox<QString>

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

Calls C++ function: QString QTextStream::read(qint64 maxlen).

C++ documentation:

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

This function was introduced in Qt 4.1.

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

source

pub unsafe fn read_all(&self) -> CppBox<QString>

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.

Calls C++ function: QString QTextStream::readAll().

C++ documentation:

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

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

See also readLine().

source

pub unsafe fn read_line_1a(&self, maxlen: i64) -> CppBox<QString>

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.

Calls C++ function: QString QTextStream::readLine(qint64 maxlen = …).

C++ documentation:

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.

The returned line has no trailing end-of-line characters ("\n" or "\r\n"), so calling QString::trimmed() can be 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().

source

pub unsafe fn read_line_0a(&self) -> CppBox<QString>

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.

Calls C++ function: QString QTextStream::readLine().

C++ documentation:

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.

The returned line has no trailing end-of-line characters ("\n" or "\r\n"), so calling QString::trimmed() can be 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().

source

pub unsafe fn read_line_into_2a( &self, line: impl CastInto<Ptr<QString>>, maxlen: i64 ) -> bool

Reads one line of text from the stream into line. If line is 0, the read line is not stored.

Calls C++ function: bool QTextStream::readLineInto(QString* line, qint64 maxlen = …).

C++ documentation:

Reads one line of text from the stream into line. If line is 0, the read line is not stored.

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.

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

If line has sufficient capacity for the data that is about to be read, this function may not need to allocate new memory. Because of this, it can be faster than readLine().

Returns false if the stream has read to the end of the file or an error has occurred; otherwise returns true. The contents in line before the call are discarded in any case.

This function was introduced in Qt 5.5.

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

source

pub unsafe fn read_line_into_1a( &self, line: impl CastInto<Ptr<QString>> ) -> bool

Reads one line of text from the stream into line. If line is 0, the read line is not stored.

Calls C++ function: bool QTextStream::readLineInto(QString* line).

C++ documentation:

Reads one line of text from the stream into line. If line is 0, the read line is not stored.

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.

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

If line has sufficient capacity for the data that is about to be read, this function may not need to allocate new memory. Because of this, it can be faster than readLine().

Returns false if the stream has read to the end of the file or an error has occurred; otherwise returns true. The contents in line before the call are discarded in any case.

This function was introduced in Qt 5.5.

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

source

pub unsafe fn real_number_notation(&self) -> RealNumberNotation

Returns the current real number notation.

Calls C++ function: QTextStream::RealNumberNotation QTextStream::realNumberNotation() const.

C++ documentation:

Returns the current real number notation.

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

source

pub unsafe fn real_number_precision(&self) -> c_int

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

Calls C++ function: int QTextStream::realNumberPrecision() const.

C++ documentation:

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().

source

pub unsafe fn reset(&self)

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

Calls C++ function: void QTextStream::reset().

C++ documentation:

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

source

pub unsafe fn reset_status(&self)

Resets the status of the text stream.

Calls C++ function: void QTextStream::resetStatus().

C++ documentation:

Resets the status of the text stream.

This function was introduced in Qt 4.1.

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

source

pub unsafe fn seek(&self, pos: i64) -> bool

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

Calls C++ function: bool QTextStream::seek(qint64 pos).

C++ documentation:

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

source

pub unsafe fn set_auto_detect_unicode(&self, enabled: bool)

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.

Calls C++ function: void QTextStream::setAutoDetectUnicode(bool enabled).

C++ documentation:

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().

source

pub unsafe fn set_codec_q_text_codec( &self, codec: impl CastInto<Ptr<QTextCodec>> )

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.

Calls C++ function: void QTextStream::setCodec(QTextCodec* codec).

C++ documentation:

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

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

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

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

source

pub unsafe fn set_codec_char(&self, codec_name: *const c_char)

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.

Calls C++ function: void QTextStream::setCodec(const char* codecName).

C++ documentation:

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:

QTextStream out(&file); out.setCodec(“UTF-8”);

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

source

pub unsafe fn set_device(&self, device: impl CastInto<Ptr<QIODevice>>)

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

Calls C++ function: void QTextStream::setDevice(QIODevice* device).

C++ documentation:

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

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

See also device() and setString().

source

pub unsafe fn set_field_alignment(&self, alignment: FieldAlignment)

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.

Calls C++ function: void QTextStream::setFieldAlignment(QTextStream::FieldAlignment alignment).

C++ documentation:

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().

source

pub unsafe fn set_field_width(&self, width: c_int)

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.

Calls C++ function: void QTextStream::setFieldWidth(int width).

C++ documentation:

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().

source

pub unsafe fn set_generate_byte_order_mark(&self, generate: bool)

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.

Calls C++ function: void QTextStream::setGenerateByteOrderMark(bool generate).

C++ documentation:

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().

source

pub unsafe fn set_integer_base(&self, base: c_int)

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.

Calls C++ function: void QTextStream::setIntegerBase(int base).

C++ documentation:

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().

source

pub unsafe fn set_locale(&self, locale: impl CastInto<Ref<QLocale>>)

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

Calls C++ function: void QTextStream::setLocale(const QLocale& locale).

C++ documentation:

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.

This function was introduced in Qt 4.5.

See also locale().

source

pub unsafe fn set_number_flags(&self, flags: QFlags<NumberFlag>)

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).

Calls C++ function: void QTextStream::setNumberFlags(QFlags<QTextStream::NumberFlag> flags).

C++ documentation:

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().

source

pub unsafe fn set_pad_char(&self, ch: impl CastInto<Ref<QChar>>)

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.

Calls C++ function: void QTextStream::setPadChar(QChar ch).

C++ documentation:

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:

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().

source

pub unsafe fn set_real_number_notation(&self, notation: RealNumberNotation)

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.

Calls C++ function: void QTextStream::setRealNumberNotation(QTextStream::RealNumberNotation notation).

C++ documentation:

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().

source

pub unsafe fn set_real_number_precision(&self, precision: c_int)

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

Calls C++ function: void QTextStream::setRealNumberPrecision(int precision).

C++ documentation:

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().

source

pub unsafe fn set_status(&self, status: Status)

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

Calls C++ function: void QTextStream::setStatus(QTextStream::Status status).

C++ documentation:

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

Subsequent calls to setStatus() are ignored until resetStatus() is called.

This function was introduced in Qt 4.1.

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

source

pub unsafe fn set_string_2a( &self, string: impl CastInto<Ptr<QString>>, open_mode: QFlags<OpenModeFlag> )

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

Calls C++ function: void QTextStream::setString(QString* string, QFlags<QIODevice::OpenModeFlag> openMode = …).

C++ documentation:

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().

source

pub unsafe fn set_string_1a(&self, string: impl CastInto<Ptr<QString>>)

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

Calls C++ function: void QTextStream::setString(QString* string).

C++ documentation:

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().

source

pub unsafe fn shl_short(&self, i: c_short) -> Ref<QTextStream>

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().

Calls C++ function: QTextStream& QTextStream::operator<<(short i).

C++ documentation:

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().

source

pub unsafe fn shl_ushort(&self, i: c_ushort) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(unsigned short i).

C++ documentation:

This is an overloaded function.

Writes the unsigned short i to the stream.

source

pub unsafe fn shl_int(&self, i: c_int) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(int i).

C++ documentation:

This is an overloaded function.

Writes the signed int i to the stream.

source

pub unsafe fn shl_uint(&self, i: c_uint) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(unsigned int i).

C++ documentation:

This is an overloaded function.

Writes the unsigned int i to the stream.

source

pub unsafe fn shl_long(&self, i: c_long) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(long i).

C++ documentation:

This is an overloaded function.

Writes the signed long i to the stream.

source

pub unsafe fn shl_ulong(&self, i: c_ulong) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(unsigned long i).

C++ documentation:

This is an overloaded function.

Writes the unsigned long i to the stream.

source

pub unsafe fn shl_u64(&self, i: u64) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(qulonglong i).

C++ documentation:

This is an overloaded function.

Writes the qulonglong i to the stream.

source

pub unsafe fn shl_double(&self, f: c_double) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(double f).

C++ documentation:

This is an overloaded function.

Writes the double f to the stream.

source

pub unsafe fn shr_short(&self, i: *mut c_short) -> Ref<QTextStream>

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.

Calls C++ function: QTextStream& QTextStream::operator>>(short& i).

C++ documentation:

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

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

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

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

Leading whitespace is skipped.

source

pub unsafe fn shr_ushort(&self, i: *mut c_ushort) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(unsigned short& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the unsigned short i.

source

pub unsafe fn shr_int(&self, i: *mut c_int) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(int& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the signed int i.

source

pub unsafe fn shr_uint(&self, i: *mut c_uint) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(unsigned int& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the unsigned int i.

source

pub unsafe fn shr_long(&self, i: *mut c_long) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(long& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the signed long i.

source

pub unsafe fn shr_ulong(&self, i: *mut c_ulong) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(unsigned long& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the unsigned long i.

source

pub unsafe fn shr_u64(&self, i: *mut u64) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(qulonglong& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the qulonglong i.

source

pub unsafe fn shr_double(&self, f: *mut c_double) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(double& f).

C++ documentation:

This is an overloaded function.

Stores the real number in the double f.

source

pub unsafe fn shr_char(&self, c: *mut c_char) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(char* c).

C++ documentation:

This is an overloaded function.

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

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

If possible, use the QByteArray operator instead.

source

pub unsafe fn skip_white_space(&self)

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.

Calls C++ function: void QTextStream::skipWhiteSpace().

C++ documentation:

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>>().

source

pub unsafe fn status(&self) -> Status

Returns the status of the text stream.

Calls C++ function: QTextStream::Status QTextStream::status() const.

C++ documentation:

Returns the status of the text stream.

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

source

pub unsafe fn string(&self) -> Ptr<QString>

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

Calls C++ function: QString* QTextStream::string() const.

C++ documentation:

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

See also setString() and device().

Trait Implementations§

source§

impl CppDeletable for QTextStream

source§

unsafe fn delete(&self)

Destroys the QTextStream.

Calls C++ function: virtual [destructor] void QTextStream::~QTextStream().

C++ documentation:

Destroys the QTextStream.

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

source§

impl Shl<*const c_void> for &QTextStream

source§

fn shl(self, ptr: *const c_void) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(const void* ptr).

C++ documentation:

This is an overloaded function.

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

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<*const i8> for &QTextStream

source§

fn shl(self, c: *const c_char) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(const char* c).

C++ documentation:

This is an overloaded function.

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

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.

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QByteArray>> for &QTextStream

source§

fn shl(self, array: Ref<QByteArray>) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(const QByteArray& array).

C++ documentation:

This is an overloaded function.

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

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QChar>> for &QTextStream

source§

fn shl(self, ch: Ref<QChar>) -> Ref<QTextStream>

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

Calls C++ function: QTextStream& QTextStream::operator<<(QChar ch).

C++ documentation:

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

See also setFieldWidth().

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QLatin1String>> for &QTextStream

source§

fn shl(self, s: Ref<QLatin1String>) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(QLatin1String s).

C++ documentation:

This is an overloaded function.

Writes string to the stream, and returns a reference to the QTextStream.

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QString>> for &QTextStream

source§

fn shl(self, s: Ref<QString>) -> Ref<QTextStream>

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.

Calls C++ function: QTextStream& QTextStream::operator<<(const QString& s).

C++ documentation:

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().

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QStringRef>> for &QTextStream

source§

fn shl(self, s: Ref<QStringRef>) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(const QStringRef& s).

C++ documentation:

This is an overloaded function.

Writes string to the stream, and returns a reference to the QTextStream.

This function was introduced in Qt 5.6.

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QStringView>> for &QTextStream

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.
source§

fn shl(self, s: Ref<QStringView>) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(QStringView s).

C++ documentation:

This is an overloaded function.

Writes string to the stream, and returns a reference to the QTextStream.

This function was introduced in Qt 5.12.

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<Ref<QTextStreamManipulator>> for &QTextStream

source§

fn shl(self, m: Ref<QTextStreamManipulator>) -> Ref<QTextStream>

Writes bit array ba to stream out.

Calls C++ function: QTextStream& operator<<(QTextStream& s, QTextStreamManipulator m).

Warning: no exact match found in C++ documentation. Below is the C++ documentation for QDataStream &operator<<(QDataStream &out, const QBitArray &ba):

Writes bit array ba to stream out.

See also Format of the QDataStream operators.

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<f32> for &QTextStream

source§

fn shl(self, f: c_float) -> Ref<QTextStream>

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().

Calls C++ function: QTextStream& QTextStream::operator<<(float f).

C++ documentation:

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().

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<i64> for &QTextStream

source§

fn shl(self, i: i64) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(qlonglong i).

C++ documentation:

This is an overloaded function.

Writes the qlonglong i to the stream.

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shl<i8> for &QTextStream

source§

fn shl(self, ch: c_char) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator<<(char ch).

C++ documentation:

This is an overloaded function.

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

§

type Output = Ref<QTextStream>

The resulting type after applying the << operator.
source§

impl Shr<*mut f32> for &QTextStream

source§

fn shr(self, f: *mut c_float) -> Ref<QTextStream>

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.

Calls C++ function: QTextStream& QTextStream::operator>>(float& f).

C++ documentation:

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.

§

type Output = Ref<QTextStream>

The resulting type after applying the >> operator.
source§

impl Shr<*mut i64> for &QTextStream

source§

fn shr(self, i: *mut i64) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(qlonglong& i).

C++ documentation:

This is an overloaded function.

Stores the integer in the qlonglong i.

§

type Output = Ref<QTextStream>

The resulting type after applying the >> operator.
source§

impl Shr<*mut i8> for &QTextStream

source§

fn shr(self, ch: *mut c_char) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(char& ch).

C++ documentation:

This is an overloaded function.

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

See also QChar::toLatin1().

§

type Output = Ref<QTextStream>

The resulting type after applying the >> operator.
source§

impl Shr<Ref<QByteArray>> for &QTextStream

source§

fn shr(self, array: Ref<QByteArray>) -> Ref<QTextStream>

This is an overloaded function.

Calls C++ function: QTextStream& QTextStream::operator>>(QByteArray& array).

C++ documentation:

This is an overloaded function.

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

See also QString::toLatin1().

§

type Output = Ref<QTextStream>

The resulting type after applying the >> operator.
source§

impl Shr<Ref<QChar>> for &QTextStream

source§

fn shr(self, ch: Ref<QChar>) -> Ref<QTextStream>

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

Calls C++ function: QTextStream& QTextStream::operator>>(QChar& ch).

C++ documentation:

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


  QTextStream in(file);
  QChar ch1, ch2, ch3;
  in >> ch1 >> ch2 >> ch3;

Whitespace is not skipped.

§

type Output = Ref<QTextStream>

The resulting type after applying the >> operator.
source§

impl Shr<Ref<QString>> for &QTextStream

source§

fn shr(self, s: Ref<QString>) -> Ref<QTextStream>

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).

Calls C++ function: QTextStream& QTextStream::operator>>(QString& s).

C++ documentation:

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.

§

type Output = Ref<QTextStream>

The resulting type after applying the >> operator.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.