Qt 4.8
Public Types | Public Functions | Properties | Related Functions | List of all members
QTextStream Class Reference

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

#include <qtextstream.h>

Public Types

enum  FieldAlignment { AlignLeft, AlignRight, AlignCenter, AlignAccountingStyle }
 This enum specifies how to align text in fields when the field is wider than the text that occupies it. More...
 
enum  NumberFlag {
  ShowBase = 0x1, ForcePoint = 0x2, ForceSign = 0x4, UppercaseBase = 0x8,
  UppercaseDigits = 0x10
}
 This enum specifies various flags that can be set to affect the output of integers, floats, and doubles. More...
 
enum  RealNumberNotation { SmartNotation, FixedNotation, ScientificNotation }
 This enum specifies which notations to use for expressing float and double as strings. More...
 
enum  Status { Ok, ReadPastEnd, ReadCorruptData, WriteFailed }
 This enum describes the current status of the text stream. More...
 

Public Functions

bool atEnd () const
 Returns true if there is no more data to be read from the QTextStream; otherwise returns false. More...
 
bool autoDetectUnicode () const
 Returns true if automatic Unicode detection is enabled, otherwise returns false. More...
 
QTextCodeccodec () const
 Returns the codec that is current assigned to the stream. More...
 
QIODevicedevice () const
 Returns the current device associated with the QTextStream, or 0 if no device has been assigned. More...
 
FieldAlignment fieldAlignment () const
 Returns the current field alignment. More...
 
int fieldWidth () const
 Returns the current field width. More...
 
void flush ()
 Flushes any buffered data waiting to be written to the device. More...
 
bool generateByteOrderMark () const
 Returns true if QTextStream is set to generate the UTF BOM (Byte Order Mark) when using a UTF codec; otherwise returns false. More...
 
int integerBase () const
 Returns the current base of integers. More...
 
QLocale locale () const
 Returns the locale for this stream. More...
 
NumberFlags numberFlags () const
 Returns the current number flags. More...
 
QTextStreamoperator<< (QBool b)
 
QTextStreamoperator<< (QChar ch)
 Writes the character c to the stream, then returns a reference to the QTextStream. More...
 
QTextStreamoperator<< (char ch)
 Converts c from ASCII to a QChar, then writes it to the stream. More...
 
QTextStreamoperator<< (signed short i)
 Writes the integer number i to the stream, then returns a reference to the QTextStream. More...
 
QTextStreamoperator<< (unsigned short i)
 Writes the unsigned short i to the stream. More...
 
QTextStreamoperator<< (signed int i)
 Writes the signed int i to the stream. More...
 
QTextStreamoperator<< (unsigned int i)
 Writes the unsigned int i to the stream. More...
 
QTextStreamoperator<< (signed long i)
 Writes the signed long i to the stream. More...
 
QTextStreamoperator<< (unsigned long i)
 Writes the unsigned long i to the stream. More...
 
QTextStreamoperator<< (qlonglong i)
 Writes the qlonglong i to the stream. More...
 
QTextStreamoperator<< (qulonglong i)
 Writes the qulonglong i to the stream. More...
 
QTextStreamoperator<< (float f)
 Writes the real number f to the stream, then returns a reference to the QTextStream. More...
 
QTextStreamoperator<< (double f)
 Writes the double f to the stream. More...
 
QTextStreamoperator<< (const QString &s)
 Writes the string string to the stream, and returns a reference to the QTextStream. More...
 
QTextStreamoperator<< (const QByteArray &array)
 Writes array to the stream. More...
 
QTextStreamoperator<< (const char *c)
 Writes the constant string pointed to by string to the stream. More...
 
QTextStreamoperator<< (const void *ptr)
 Writes ptr to the stream as a hexadecimal number with a base. More...
 
QTextStreamoperator>> (QChar &ch)
 Reads a character from the stream and stores it in c. More...
 
QTextStreamoperator>> (char &ch)
 Reads a character from the stream and stores it in c. More...
 
QTextStreamoperator>> (signed short &i)
 Reads an integer from the stream and stores it in i, then returns a reference to the QTextStream. More...
 
QTextStreamoperator>> (unsigned short &i)
 Stores the integer in the unsigned short i. More...
 
QTextStreamoperator>> (signed int &i)
 Stores the integer in the signed int i. More...
 
QTextStreamoperator>> (unsigned int &i)
 Stores the integer in the unsigned int i. More...
 
QTextStreamoperator>> (signed long &i)
 Stores the integer in the signed long i. More...
 
QTextStreamoperator>> (unsigned long &i)
 Stores the integer in the unsigned long i. More...
 
QTextStreamoperator>> (qlonglong &i)
 Stores the integer in the qlonglong i. More...
 
QTextStreamoperator>> (qulonglong &i)
 Stores the integer in the qulonglong i. More...
 
QTextStreamoperator>> (float &f)
 Reads a real number from the stream and stores it in f, then returns a reference to the QTextStream. More...
 
QTextStreamoperator>> (double &f)
 Stores the real number in the double f. More...
 
QTextStreamoperator>> (QString &s)
 Reads a word from the stream and stores it in str, then returns a reference to the stream. More...
 
QTextStreamoperator>> (QByteArray &array)
 Converts the word to ISO-8859-1, then stores it in array. More...
 
QTextStreamoperator>> (char *c)
 Stores the word in c, terminated by a '\0' character. More...
 
QChar padChar () const
 Returns the current pad character. More...
 
qint64 pos () const
 Returns the device position corresponding to the current position of the stream, or -1 if an error occurs (e. More...
 
 QTextStream ()
 Constructs a QTextStream. More...
 
 QTextStream (QIODevice *device)
 Constructs a QTextStream that operates on device. More...
 
 QTextStream (FILE *fileHandle, QIODevice::OpenMode openMode=QIODevice::ReadWrite)
 Constructs a QTextStream that operates on fileHandle, using openMode to define the open mode. More...
 
 QTextStream (QString *string, QIODevice::OpenMode openMode=QIODevice::ReadWrite)
 Constructs a QTextStream that operates on string, using openMode to define the open mode. More...
 
 QTextStream (QByteArray *array, QIODevice::OpenMode openMode=QIODevice::ReadWrite)
 Constructs a QTextStream that operates on array, using openMode to define the open mode. More...
 
 QTextStream (const QByteArray &array, QIODevice::OpenMode openMode=QIODevice::ReadOnly)
 Constructs a QTextStream that operates on array, using openMode to define the open mode. More...
 
QString read (qint64 maxlen)
 Reads at most maxlen characters from the stream, and returns the data read as a QString. More...
 
QString readAll ()
 Reads the entire content of the stream, and returns it as a QString. More...
 
QString readLine (qint64 maxlen=0)
 Reads one line of text from the stream, and returns it as a QString. More...
 
RealNumberNotation realNumberNotation () const
 Returns the current real number notation. More...
 
int realNumberPrecision () const
 Returns the current real number precision, or the number of fraction digits QTextStream will write when generating real numbers. More...
 
void reset ()
 Resets QTextStream's formatting options, bringing it back to its original constructed state. More...
 
void resetStatus ()
 Resets the status of the text stream. More...
 
bool seek (qint64 pos)
 Seeks to the position pos in the device. More...
 
void setAutoDetectUnicode (bool enabled)
 If enabled is true, QTextStream will attempt to detect Unicode encoding by peeking into the stream data to see if it can find the UTF-16 or UTF-32 BOM (Byte Order Mark). More...
 
void setCodec (QTextCodec *codec)
 Sets the codec for this stream to codec. More...
 
void setCodec (const char *codecName)
 Sets the codec for this stream to the QTextCodec for the encoding specified by codecName. More...
 
void setDevice (QIODevice *device)
 Sets the current device to device. More...
 
void setFieldAlignment (FieldAlignment alignment)
 Sets the field alignment to mode. More...
 
void setFieldWidth (int width)
 Sets the current field width to width. More...
 
void setGenerateByteOrderMark (bool generate)
 If generate is true and a UTF codec is used, QTextStream will insert the BOM (Byte Order Mark) before any data has been written to the device. More...
 
void setIntegerBase (int base)
 Sets the base of integers to base, both for reading and for generating numbers. More...
 
void setLocale (const QLocale &locale)
 Sets the locale for this stream to locale. More...
 
void setNumberFlags (NumberFlags flags)
 Sets the current number flags to flags. More...
 
void setPadChar (QChar ch)
 Sets the pad character to ch. More...
 
void setRealNumberNotation (RealNumberNotation notation)
 Sets the real number notation to notation (SmartNotation, FixedNotation, ScientificNotation). More...
 
void setRealNumberPrecision (int precision)
 Sets the precision of real numbers to precision. More...
 
void setStatus (Status status)
 Sets the status of the text stream to the status given. More...
 
void setString (QString *string, QIODevice::OpenMode openMode=QIODevice::ReadWrite)
 Sets the current string to string, using the given openMode. More...
 
void skipWhiteSpace ()
 Reads and discards whitespace from the stream until either a non-space character is detected, or until atEnd() returns true. More...
 
Status status () const
 Returns the status of the text stream. More...
 
QStringstring () const
 Returns the current string assigned to the QTextStream, or 0 if no string has been assigned. More...
 
virtual ~QTextStream ()
 Destroys the QTextStream. More...
 

Properties

QScopedPointer< QTextStreamPrivated_ptr
 

Related Functions

(Note that these are not member functions.)

QTextStreambin (QTextStream &stream)
 Calls QTextStream::setIntegerBase(2) on stream and returns stream. More...
 
QTextStreambom (QTextStream &stream)
 Toggles insertion of the Byte Order Mark on stream when QTextStream is used with a UTF codec. More...
 
QTextStreamcenter (QTextStream &stream)
 Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream. More...
 
QTextStreamdec (QTextStream &stream)
 Calls QTextStream::setIntegerBase(10) on stream and returns stream. More...
 
QTextStreamendl (QTextStream &stream)
 Writes '
' to the stream and flushes the stream. More...
 
QTextStreamfixed (QTextStream &stream)
 Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream. More...
 
QTextStreamflush (QTextStream &stream)
 Calls QTextStream::flush() on stream and returns stream. More...
 
QTextStreamforcepoint (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForcePoint) on stream and returns stream. More...
 
QTextStreamforcesign (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and returns stream. More...
 
QTextStreamhex (QTextStream &stream)
 Calls QTextStream::setIntegerBase(16) on stream and returns stream. More...
 
QTextStreamleft (QTextStream &stream)
 Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream. More...
 
QTextStreamlowercasebase (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseBase) on stream and returns stream. More...
 
QTextStreamlowercasedigits (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseDigits) on stream and returns stream. More...
 
QTextStreamnoforcepoint (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForcePoint) on stream and returns stream. More...
 
QTextStreamnoforcesign (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and returns stream. More...
 
QTextStreamnoshowbase (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and returns stream. More...
 
QTextStreamoct (QTextStream &stream)
 Calls QTextStream::setIntegerBase(8) on stream and returns stream. More...
 
QTextStreamManipulator qSetFieldWidth (int width)
 Equivalent to QTextStream::setFieldWidth(width). More...
 
QTextStreamManipulator qSetPadChar (QChar ch)
 Equivalent to QTextStream::setPadChar(ch). More...
 
QTextStreamManipulator qSetRealNumberPrecision (int precision)
 Equivalent to QTextStream::setRealNumberPrecision(precision). More...
 
QTextStreamreset (QTextStream &stream)
 Calls QTextStream::reset() on stream and returns stream. More...
 
QTextStreamright (QTextStream &stream)
 Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream. More...
 
QTextStreamscientific (QTextStream &stream)
 Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) on stream and returns stream. More...
 
QTextStreamshowbase (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and returns stream. More...
 
QTextStreamuppercasebase (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseBase) on stream and returns stream. More...
 
QTextStreamuppercasedigits (QTextStream &stream)
 Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseDigits) on stream and returns stream. More...
 
QTextStreamws (QTextStream &stream)
 Calls skipWhiteSpace() on stream and returns stream. More...
 

Detailed Description

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

Note
This class or function is reentrant.

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");
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:

QString line;
do {
line = stream.readLine();
} while (!line.isNull());

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:

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

QTextStream manipulators

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

Manipulator Description
bin Same as setIntegerBase(2).
oct Same as setIntegerBase(8).
dec Same as setIntegerBase(10).
hex Same as setIntegerBase(16).
showbase Same as setNumberFlags(numberFlags() | ShowBase).
forcesign Same as setNumberFlags(numberFlags() | ForceSign).
forcepoint Same as setNumberFlags(numberFlags() | ForcePoint).
noshowbase Same as setNumberFlags(numberFlags() & ~ShowBase).
noforcesign Same as setNumberFlags(numberFlags() & ~ForceSign).
noforcepoint Same as setNumberFlags(numberFlags() & ~ForcePoint).
uppercasebase Same as setNumberFlags(numberFlags() | UppercaseBase).
uppercasedigits Same as setNumberFlags(numberFlags() | UppercaseDigits).
lowercasebase Same as setNumberFlags(numberFlags() & ~UppercaseBase).
lowercasedigits Same as setNumberFlags(numberFlags() & ~UppercaseDigits).
fixed Same as setRealNumberNotation(FixedNotation).
scientific Same as setRealNumberNotation(ScientificNotation).
left Same as setFieldAlignment(AlignLeft).
right Same as setFieldAlignment(AlignRight).
center Same as setFieldAlignment(AlignCenter).
endl Same as operator<<('
') and flush().
flush Same as flush().
reset Same as reset().
ws Same as skipWhiteSpace().
bom Same as setGenerateByteOrderMark(true).

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

See also
QDataStream, QIODevice, QFile, QBuffer, QTcpSocket, {Codecs Example}

Definition at line 73 of file qtextstream.h.

Enumerations

◆ FieldAlignment

This enum specifies how to align text in fields when the field is wider than the text that occupies it.

  • AlignLeft Pad on the right side of fields.
  • AlignRight Pad on the left side of fields.
  • AlignCenter Pad on both sides of field.
  • AlignAccountingStyle Same as AlignRight, except that the sign of a number is flush left.
See also
setFieldAlignment()
Enumerator
AlignLeft 
AlignRight 
AlignCenter 
AlignAccountingStyle 

Definition at line 83 of file qtextstream.h.

◆ NumberFlag

This enum specifies various flags that can be set to affect the output of integers, floats, and doubles.

  • ShowBase Show the base as a prefix if the base is 16 ("0x"), 8 ("0"), or 2 ("0b").
  • ForcePoint Always put the decimal separator in numbers, even if there are no decimals.
  • ForceSign Always put the sign in numbers, even for positive numbers.
  • UppercaseBase Use uppercase versions of base prefixes ("0X", "0B").
  • UppercaseDigits Use uppercase letters for expressing digits 10 to 35 instead of lowercase.
See also
setNumberFlags()
Enumerator
ShowBase 
ForcePoint 
ForceSign 
UppercaseBase 
UppercaseDigits 

Definition at line 95 of file qtextstream.h.

◆ RealNumberNotation

This enum specifies which notations to use for expressing float and double as strings.

  • ScientificNotation Scientific notation (printf()'s e flag).
  • FixedNotation Fixed-point notation (printf()'s f flag).
  • SmartNotation Scientific or fixed-point notation, depending on which makes most sense (printf()'s g flag).
See also
setRealNumberNotation()
Enumerator
SmartNotation 
FixedNotation 
ScientificNotation 

Definition at line 78 of file qtextstream.h.

◆ Status

This enum describes the current status of the text stream.

  • Ok The text stream is operating normally.
  • ReadPastEnd The text stream has read past the end of the data in the underlying device.
  • ReadCorruptData The text stream has read corrupt data.
  • WriteFailed The text stream cannot write to the underlying device.
See also
status()
Enumerator
Ok 
ReadPastEnd 
ReadCorruptData 
WriteFailed 

Definition at line 89 of file qtextstream.h.

Constructors and Destructors

◆ QTextStream() [1/6]

QTextStream::QTextStream ( )

Constructs a QTextStream.

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

See also
setDevice(), setString()

Definition at line 1027 of file qtextstream.cpp.

Referenced by qSetRealNumberPrecision().

1028  : d_ptr(new QTextStreamPrivate(this))
1029 {
1030 #if defined (QTEXTSTREAM_DEBUG)
1031  qDebug("QTextStream::QTextStream()");
1032 #endif
1033  Q_D(QTextStream);
1034  d->status = Ok;
1035 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QTextStreamPrivate > d_ptr
Definition: qtextstream.h:261
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ QTextStream() [2/6]

QTextStream::QTextStream ( QIODevice device)
explicit

Constructs a QTextStream that operates on device.

Definition at line 1040 of file qtextstream.cpp.

1041  : d_ptr(new QTextStreamPrivate(this))
1042 {
1043 #if defined (QTEXTSTREAM_DEBUG)
1044  qDebug("QTextStream::QTextStream(QIODevice *device == *%p)",
1045  device);
1046 #endif
1047  Q_D(QTextStream);
1048  d->device = device;
1049 #ifndef QT_NO_QOBJECT
1050  d->deviceClosedNotifier.setupDevice(this, d->device);
1051 #endif
1052  d->status = Ok;
1053 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QTextStreamPrivate > d_ptr
Definition: qtextstream.h:261
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
QIODevice * device() const
Returns the current device associated with the QTextStream, or 0 if no device has been assigned...
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ QTextStream() [3/6]

QTextStream::QTextStream ( FILE *  fileHandle,
QIODevice::OpenMode  openMode = QIODevice::ReadWrite 
)
explicit

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

Internally, a QFile is created to handle the FILE pointer.

This constructor is useful for working directly with the common FILE based input and output streams: stdin, stdout and stderr. Example:

QString str;
QTextStream in(stdin);
in >> str;

Definition at line 1135 of file qtextstream.cpp.

1136  : d_ptr(new QTextStreamPrivate(this))
1137 {
1138 #if defined (QTEXTSTREAM_DEBUG)
1139  qDebug("QTextStream::QTextStream(FILE *fileHandle = %p, openMode = %d)",
1140  fileHandle, int(openMode));
1141 #endif
1142  QFile *file = new QFile;
1143  file->open(fileHandle, openMode);
1144 
1145  Q_D(QTextStream);
1146  d->device = file;
1147  d->deleteDevice = true;
1148 #ifndef QT_NO_QOBJECT
1149  d->deviceClosedNotifier.setupDevice(this, d->device);
1150 #endif
1151  d->status = Ok;
1152 }
double d
Definition: qnumeric_p.h:62
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
QScopedPointer< QTextStreamPrivate > d_ptr
Definition: qtextstream.h:261
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ QTextStream() [4/6]

QTextStream::QTextStream ( QString string,
QIODevice::OpenMode  openMode = QIODevice::ReadWrite 
)
explicit

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

Definition at line 1059 of file qtextstream.cpp.

1060  : d_ptr(new QTextStreamPrivate(this))
1061 {
1062 #if defined (QTEXTSTREAM_DEBUG)
1063  qDebug("QTextStream::QTextStream(QString *string == *%p, openMode = %d)",
1064  string, int(openMode));
1065 #endif
1066  Q_D(QTextStream);
1067  d->string = string;
1068  d->stringOpenMode = openMode;
1069  d->status = Ok;
1070 }
QString * string() const
Returns the current string assigned to the QTextStream, or 0 if no string has been assigned...
double d
Definition: qnumeric_p.h:62
QScopedPointer< QTextStreamPrivate > d_ptr
Definition: qtextstream.h:261
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ QTextStream() [5/6]

QTextStream::QTextStream ( QByteArray array,
QIODevice::OpenMode  openMode = QIODevice::ReadWrite 
)
explicit

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

Internally, the array is wrapped by a QBuffer.

Definition at line 1077 of file qtextstream.cpp.

1078  : d_ptr(new QTextStreamPrivate(this))
1079 {
1080 #if defined (QTEXTSTREAM_DEBUG)
1081  qDebug("QTextStream::QTextStream(QByteArray *array == *%p, openMode = %d)",
1082  array, int(openMode));
1083 #endif
1084  Q_D(QTextStream);
1085  d->device = new QBuffer(array);
1086  d->device->open(openMode);
1087  d->deleteDevice = true;
1088 #ifndef QT_NO_QOBJECT
1089  d->deviceClosedNotifier.setupDevice(this, d->device);
1090 #endif
1091  d->status = Ok;
1092 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QTextStreamPrivate > d_ptr
Definition: qtextstream.h:261
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ QTextStream() [6/6]

QTextStream::QTextStream ( const QByteArray array,
QIODevice::OpenMode  openMode = QIODevice::ReadOnly 
)
explicit

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

The array is accessed as read-only, regardless of the values in openMode.

This constructor is convenient for working on constant strings. Example:

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

Definition at line 1104 of file qtextstream.cpp.

1105  : d_ptr(new QTextStreamPrivate(this))
1106 {
1107 #if defined (QTEXTSTREAM_DEBUG)
1108  qDebug("QTextStream::QTextStream(const QByteArray &array == *(%p), openMode = %d)",
1109  &array, int(openMode));
1110 #endif
1111  QBuffer *buffer = new QBuffer;
1112  buffer->setData(array);
1113  buffer->open(openMode);
1114 
1115  Q_D(QTextStream);
1116  d->device = buffer;
1117  d->deleteDevice = true;
1118 #ifndef QT_NO_QOBJECT
1119  d->deviceClosedNotifier.setupDevice(this, d->device);
1120 #endif
1121  d->status = Ok;
1122 }
double d
Definition: qnumeric_p.h:62
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition: qbuffer.cpp:315
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
QScopedPointer< QTextStreamPrivate > d_ptr
Definition: qtextstream.h:261
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ ~QTextStream()

QTextStream::~QTextStream ( )
virtual

Destroys the QTextStream.

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

Definition at line 1160 of file qtextstream.cpp.

Referenced by lowercasebase(), lowercasedigits(), noforcepoint(), noforcesign(), and noshowbase().

1161 {
1162  Q_D(QTextStream);
1163 #if defined (QTEXTSTREAM_DEBUG)
1164  qDebug("QTextStream::~QTextStream()");
1165 #endif
1166  if (!d->writeBuffer.isEmpty())
1167  d->flushWriteBuffer();
1168 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

Functions

◆ atEnd()

bool QTextStream::atEnd ( ) const

Returns true if there is no more data to be read from the QTextStream; otherwise returns false.

This is similar to, but not the same as calling QIODevice::atEnd(), as QTextStream also takes into account its internal Unicode buffer.

Definition at line 1646 of file qtextstream.cpp.

Referenced by QMacPasteboardMimeVCard::convertFromMime(), getLocations(), QGtkStylePrivate::getThemeName(), getVariables(), launchWebBrowser(), qt_parseQconfig(), readConf(), readSourceFile(), and trimmed().

1647 {
1648  Q_D(const QTextStream);
1649  CHECK_VALID_STREAM(true);
1650 
1651  if (d->string)
1652  return d->string->size() == d->stringOffset;
1653  return d->readBuffer.isEmpty() && d->device->atEnd();
1654 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ autoDetectUnicode()

bool QTextStream::autoDetectUnicode ( ) const

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

Automatic Unicode detection is enabled by default.

See also
setAutoDetectUnicode(), setCodec()

Definition at line 3215 of file qtextstream.cpp.

3216 {
3217  Q_D(const QTextStream);
3218  return d->autoDetectUnicode;
3219 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ codec()

QTextCodec * QTextStream::codec ( ) const

Returns the codec that is current assigned to the stream.

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

Definition at line 3186 of file qtextstream.cpp.

Referenced by encodeText(), QDomDocumentPrivate::saveDocument(), and setCodec().

3187 {
3188  Q_D(const QTextStream);
3189  return d->codec;
3190 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ device()

QIODevice * QTextStream::device ( ) const

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

See also
setDevice(), string()

Definition at line 1352 of file qtextstream.cpp.

Referenced by QTextStream(), and setDevice().

1353 {
1354  Q_D(const QTextStream);
1355  return d->device;
1356 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ fieldAlignment()

QTextStream::FieldAlignment QTextStream::fieldAlignment ( ) const

Returns the current field alignment.

See also
setFieldAlignment(), fieldWidth()

Definition at line 1415 of file qtextstream.cpp.

1416 {
1417  Q_D(const QTextStream);
1418  return d->fieldAlignment;
1419 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ fieldWidth()

int QTextStream::fieldWidth ( ) const

Returns the current field width.

See also
setFieldWidth()

Definition at line 1476 of file qtextstream.cpp.

1477 {
1478  Q_D(const QTextStream);
1479  return d->fieldWidth;
1480 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ flush()

void QTextStream::flush ( )

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

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

Definition at line 1193 of file qtextstream.cpp.

Referenced by QMacPasteboardMimeVCard::convertFromMime(), endl(), flush(), QDeviceClosedNotifier::flushStream(), QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::outputGraph(), setDevice(), and setString().

1194 {
1195  Q_D(QTextStream);
1196  d->flushWriteBuffer();
1197 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ generateByteOrderMark()

bool QTextStream::generateByteOrderMark ( ) const

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

UTF BOM generation is set to false by default.

See also
setGenerateByteOrderMark()

Definition at line 3247 of file qtextstream.cpp.

3248 {
3249  Q_D(const QTextStream);
3250  return (d->writeConverterState.flags & QTextCodec::IgnoreHeader) == 0;
3251 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ integerBase()

int QTextStream::integerBase ( ) const

Returns the current base of integers.

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

See also
setIntegerBase(), QString::number(), numberFlags()

Definition at line 1529 of file qtextstream.cpp.

Referenced by QTextStreamPrivate::getNumber(), and QTextStreamPrivate::putNumber().

1530 {
1531  Q_D(const QTextStream);
1532  return d->integerBase;
1533 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ locale()

QLocale QTextStream::locale ( ) const

Returns the locale for this stream.

Since
4.5

The default locale is C.

See also
setLocale()

Definition at line 3285 of file qtextstream.cpp.

Referenced by QTextStreamPrivate::getNumber(), QTextStreamPrivate::getReal(), QTextStreamPrivate::putNumber(), and setLocale().

3286 {
3287  Q_D(const QTextStream);
3288  return d->locale;
3289 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ numberFlags()

QTextStream::NumberFlags QTextStream::numberFlags ( ) const

Returns the current number flags.

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

Definition at line 1501 of file qtextstream.cpp.

Referenced by forcepoint(), forcesign(), locale(), lowercasebase(), lowercasedigits(), noforcepoint(), noforcesign(), noshowbase(), operator<<(), QTextStreamPrivate::putNumber(), showbase(), uppercasebase(), and uppercasedigits().

1502 {
1503  Q_D(const QTextStream);
1504  return d->numberFlags;
1505 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator<<() [1/17]

QTextStream & QTextStream::operator<< ( QBool  b)
Warning
This function is not part of the public interface. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2388 of file qtextstream.cpp.

2389 {
2390  return *this << bool(b);
2391 }

◆ operator<<() [2/17]

QTextStream & QTextStream::operator<< ( QChar  c)

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

See also
setFieldWidth()

Definition at line 2399 of file qtextstream.cpp.

2400 {
2401  Q_D(QTextStream);
2402  CHECK_VALID_STREAM(*this);
2403  d->putString(QString(c));
2404  return *this;
2405 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator<<() [3/17]

QTextStream & QTextStream::operator<< ( char  c)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2415 of file qtextstream.cpp.

2416 {
2417  Q_D(QTextStream);
2418  CHECK_VALID_STREAM(*this);
2419  d->putString(QString(QChar::fromAscii(c)));
2420  return *this;
2421 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
unsigned char c[8]
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
static QChar fromAscii(char c)
Converts the ASCII character c to its equivalent QChar.
Definition: qchar.cpp:1521

◆ operator<<() [4/17]

QTextStream & QTextStream::operator<< ( signed short  i)

Writes the integer number i to the stream, then returns a reference to the QTextStream.

By default, the number is stored in decimal form, but you can also set the base by calling setIntegerBase().

See also
setFieldWidth(), setNumberFlags()

Definition at line 2431 of file qtextstream.cpp.

2432 {
2433  Q_D(QTextStream);
2434  CHECK_VALID_STREAM(*this);
2435  d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0);
2436  return *this;
2437 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952
qint64 qlonglong
Definition: qglobal.h:951

◆ operator<<() [5/17]

QTextStream & QTextStream::operator<< ( unsigned short  i)

Writes the unsigned short i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2447 of file qtextstream.cpp.

2448 {
2449  Q_D(QTextStream);
2450  CHECK_VALID_STREAM(*this);
2451  d->putNumber((qulonglong)i, false);
2452  return *this;
2453 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952

◆ operator<<() [6/17]

QTextStream & QTextStream::operator<< ( signed int  i)

Writes the signed int i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2463 of file qtextstream.cpp.

2464 {
2465  Q_D(QTextStream);
2466  CHECK_VALID_STREAM(*this);
2467  d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0);
2468  return *this;
2469 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952
qint64 qlonglong
Definition: qglobal.h:951

◆ operator<<() [7/17]

QTextStream & QTextStream::operator<< ( unsigned int  i)

Writes the unsigned int i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2479 of file qtextstream.cpp.

2480 {
2481  Q_D(QTextStream);
2482  CHECK_VALID_STREAM(*this);
2483  d->putNumber((qulonglong)i, false);
2484  return *this;
2485 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952

◆ operator<<() [8/17]

QTextStream & QTextStream::operator<< ( signed long  i)

Writes the signed long i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2495 of file qtextstream.cpp.

2496 {
2497  Q_D(QTextStream);
2498  CHECK_VALID_STREAM(*this);
2499  d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0);
2500  return *this;
2501 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952
qint64 qlonglong
Definition: qglobal.h:951

◆ operator<<() [9/17]

QTextStream & QTextStream::operator<< ( unsigned long  i)

Writes the unsigned long i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2511 of file qtextstream.cpp.

2512 {
2513  Q_D(QTextStream);
2514  CHECK_VALID_STREAM(*this);
2515  d->putNumber((qulonglong)i, false);
2516  return *this;
2517 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952

◆ operator<<() [10/17]

QTextStream & QTextStream::operator<< ( qlonglong  i)

Writes the qlonglong i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2527 of file qtextstream.cpp.

2528 {
2529  Q_D(QTextStream);
2530  CHECK_VALID_STREAM(*this);
2531  d->putNumber((qulonglong)qAbs(i), i < 0);
2532  return *this;
2533 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
quint64 qulonglong
Definition: qglobal.h:952

◆ operator<<() [11/17]

QTextStream & QTextStream::operator<< ( qulonglong  i)

Writes the qulonglong i to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2543 of file qtextstream.cpp.

2544 {
2545  Q_D(QTextStream);
2546  CHECK_VALID_STREAM(*this);
2547  d->putNumber(i, false);
2548  return *this;
2549 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator<<() [12/17]

QTextStream & QTextStream::operator<< ( float  f)

Writes the real number f to the stream, then returns a reference to the QTextStream.

By default, QTextStream stores it using SmartNotation, with up to 6 digits of precision. You can change the textual representation QTextStream will use for real numbers by calling setRealNumberNotation(), setRealNumberPrecision() and setNumberFlags().

See also
setFieldWidth(), setRealNumberNotation(), setRealNumberPrecision(), setNumberFlags()

Definition at line 2562 of file qtextstream.cpp.

2563 {
2564  return *this << double(f);
2565 }

◆ operator<<() [13/17]

QTextStream & QTextStream::operator<< ( double  f)

Writes the double f to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2575 of file qtextstream.cpp.

2576 {
2577  Q_D(QTextStream);
2578  CHECK_VALID_STREAM(*this);
2579 
2581  switch (realNumberNotation()) {
2582  case FixedNotation:
2584  break;
2585  case ScientificNotation:
2587  break;
2588  case SmartNotation:
2590  break;
2591  }
2592 
2593  uint flags = 0;
2594  if (numberFlags() & ShowBase)
2595  flags |= QLocalePrivate::ShowBase;
2596  if (numberFlags() & ForceSign)
2598  if (numberFlags() & UppercaseBase)
2600  if (numberFlags() & UppercaseDigits)
2601  flags |= QLocalePrivate::CapitalEorX;
2602  if (numberFlags() & ForcePoint)
2603  flags |= QLocalePrivate::Alternate;
2604 
2605  const QLocalePrivate *dd = d->locale.d();
2606  QString num = dd->doubleToString(f, d->realNumberPrecision, form, -1, flags);
2607  d->putString(num, true);
2608  return *this;
2609 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
static QString doubleToString(const QChar zero, const QChar plus, const QChar minus, const QChar exponent, const QChar group, const QChar decimal, double d, int precision, DoubleForm form, int width, unsigned flags)
Definition: qlocale.cpp:2613
unsigned int uint
Definition: qglobal.h:996
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
NumberFlags numberFlags() const
Returns the current number flags.
RealNumberNotation realNumberNotation() const
Returns the current real number notation.

◆ operator<<() [14/17]

QTextStream & QTextStream::operator<< ( const QString string)

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

The string is first encoded using the assigned codec (the default codec is QTextCodec::codecForLocale()) before it is written to the stream.

See also
setFieldWidth(), setCodec()

Definition at line 2619 of file qtextstream.cpp.

2620 {
2621  Q_D(QTextStream);
2622  CHECK_VALID_STREAM(*this);
2623  d->putString(string);
2624  return *this;
2625 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator<<() [15/17]

QTextStream & QTextStream::operator<< ( const QByteArray array)

Writes array to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The contents of array are converted with QString::fromAscii().

Definition at line 2636 of file qtextstream.cpp.

2637 {
2638  Q_D(QTextStream);
2639  CHECK_VALID_STREAM(*this);
2640  d->putString(QString::fromAscii(array.constData(), array.length()));
2641  return *this;
2642 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
#define Q_D(Class)
Definition: qglobal.h:2482
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator<<() [16/17]

QTextStream & QTextStream::operator<< ( const char *  string)

Writes the constant string pointed to by string to the stream.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

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.

Definition at line 2660 of file qtextstream.cpp.

2661 {
2662  Q_D(QTextStream);
2663  CHECK_VALID_STREAM(*this);
2664  d->putString(QLatin1String(string));
2665  return *this;
2666 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator<<() [17/17]

QTextStream & QTextStream::operator<< ( const void *  ptr)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2677 of file qtextstream.cpp.

2678 {
2679  Q_D(QTextStream);
2680  CHECK_VALID_STREAM(*this);
2681  int oldBase = d->integerBase;
2682  NumberFlags oldFlags = d->numberFlags;
2683  d->integerBase = 16;
2684  d->numberFlags |= ShowBase;
2685  d->putNumber(reinterpret_cast<quintptr>(ptr), false);
2686  d->integerBase = oldBase;
2687  d->numberFlags = oldFlags;
2688  return *this;
2689 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
const T * ptr(const T &t)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator>>() [1/15]

QTextStream & QTextStream::operator>> ( QChar c)

Reads a character from the stream and stores it in c.

Returns a reference to the QTextStream, so several operators can be nested. Example:

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

Whitespace is not skipped.

Definition at line 2061 of file qtextstream.cpp.

2062 {
2063  Q_D(QTextStream);
2064  CHECK_VALID_STREAM(*this);
2065  d->scan(0, 0, 0, QTextStreamPrivate::NotSpace);
2066  if (!d->getChar(&c))
2068  return *this;
2069 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
void setStatus(Status status)
Sets the status of the text stream to the status given.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ operator>>() [2/15]

QTextStream & QTextStream::operator>> ( char &  c)

Reads a character from the stream and stores it in c.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The character from the stream is converted to ISO-5589-1 before it is stored.

See also
QChar::toLatin1()

Definition at line 2083 of file qtextstream.cpp.

2084 {
2085  QChar ch;
2086  *this >> ch;
2087  c = ch.toLatin1();
2088  return *this;
2089 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376

◆ operator>>() [3/15]

QTextStream & QTextStream::operator>> ( signed short &  i)

Reads an integer from the stream and stores it in i, then returns a reference to the QTextStream.

The number is cast to the correct type before it is stored. If no number was detected on the stream, i is set to 0.

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

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

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

Leading whitespace is skipped.

Definition at line 2115 of file qtextstream.cpp.

2116 {
2118 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)

◆ operator>>() [4/15]

QTextStream & QTextStream::operator>> ( unsigned short &  i)

Stores the integer in the unsigned short i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2128 of file qtextstream.cpp.

2129 {
2130  IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned short);
2131 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)

◆ operator>>() [5/15]

QTextStream & QTextStream::operator>> ( signed int &  i)

Stores the integer in the signed int i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2141 of file qtextstream.cpp.

2142 {
2144 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)

◆ operator>>() [6/15]

QTextStream & QTextStream::operator>> ( unsigned int &  i)

Stores the integer in the unsigned int i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2154 of file qtextstream.cpp.

2155 {
2157 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)

◆ operator>>() [7/15]

QTextStream & QTextStream::operator>> ( signed long &  i)

Stores the integer in the signed long i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2167 of file qtextstream.cpp.

2168 {
2170 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)

◆ operator>>() [8/15]

QTextStream & QTextStream::operator>> ( unsigned long &  i)

Stores the integer in the unsigned long i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2180 of file qtextstream.cpp.

2181 {
2182  IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned long);
2183 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)

◆ operator>>() [9/15]

QTextStream & QTextStream::operator>> ( qlonglong i)

Stores the integer in the qlonglong i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2193 of file qtextstream.cpp.

2194 {
2196 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)
qint64 qlonglong
Definition: qglobal.h:951

◆ operator>>() [10/15]

QTextStream & QTextStream::operator>> ( qulonglong i)

Stores the integer in the qulonglong i.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2206 of file qtextstream.cpp.

2207 {
2209 }
#define IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(type)
quint64 qulonglong
Definition: qglobal.h:952

◆ operator>>() [11/15]

QTextStream & QTextStream::operator>> ( float &  f)

Reads a real number from the stream and stores it in f, then returns a reference to the QTextStream.

The number is cast to the correct type. If no real number is detect on the stream, f is set to 0.0.

As a special exception, QTextStream allows the strings "nan" and "inf" to represent NAN and INF floats or doubles.

Leading whitespace is skipped.

Definition at line 2222 of file qtextstream.cpp.

2223 {
2225 }
#define IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(type)

◆ operator>>() [12/15]

QTextStream & QTextStream::operator>> ( double &  f)

Stores the real number in the double f.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 2235 of file qtextstream.cpp.

2236 {
2238 }
#define IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(type)

◆ operator>>() [13/15]

QTextStream & QTextStream::operator>> ( QString str)

Reads a word from the stream and stores it in str, then returns a reference to the stream.

Words are separated by whitespace (i.e., all characters for which QChar::isSpace() returns true).

Leading whitespace is skipped.

Definition at line 2247 of file qtextstream.cpp.

2248 {
2249  Q_D(QTextStream);
2250  CHECK_VALID_STREAM(*this);
2251 
2252  str.clear();
2253  d->scan(0, 0, 0, QTextStreamPrivate::NotSpace);
2254  d->consumeLastToken();
2255 
2256  const QChar *ptr;
2257  int length;
2258  if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
2260  return *this;
2261  }
2262 
2263  str = QString(ptr, length);
2264  d->consumeLastToken();
2265  return *this;
2266 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
void setStatus(Status status)
Sets the status of the text stream to the status given.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * ptr(const T &t)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723

◆ operator>>() [14/15]

QTextStream & QTextStream::operator>> ( QByteArray array)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
QString::toLatin1()

Definition at line 2278 of file qtextstream.cpp.

2279 {
2280  Q_D(QTextStream);
2281  CHECK_VALID_STREAM(*this);
2282 
2283  array.clear();
2284  d->scan(0, 0, 0, QTextStreamPrivate::NotSpace);
2285  d->consumeLastToken();
2286 
2287  const QChar *ptr;
2288  int length;
2289  if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
2291  return *this;
2292  }
2293 
2294  for (int i = 0; i < length; ++i)
2295  array += ptr[i].toLatin1();
2296 
2297  d->consumeLastToken();
2298  return *this;
2299 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
void setStatus(Status status)
Sets the status of the text stream to the status given.
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * ptr(const T &t)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
void clear()
Clears the contents of the byte array and makes it empty.

◆ operator>>() [15/15]

QTextStream & QTextStream::operator>> ( char *  c)

Stores the word in c, terminated by a '\0' character.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

If no word is available, only the '\0' character is stored.

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

If possible, use the QByteArray operator instead.

Definition at line 2317 of file qtextstream.cpp.

2318 {
2319  Q_D(QTextStream);
2320  *c = 0;
2321  CHECK_VALID_STREAM(*this);
2322  d->scan(0, 0, 0, QTextStreamPrivate::NotSpace);
2323  d->consumeLastToken();
2324 
2325  const QChar *ptr;
2326  int length;
2327  if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) {
2329  return *this;
2330  }
2331 
2332  for (int i = 0; i < length; ++i)
2333  *c++ = ptr[i].toLatin1();
2334  *c = '\0';
2335  d->consumeLastToken();
2336  return *this;
2337 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
unsigned char c[8]
Definition: qnumeric_p.h:62
void setStatus(Status status)
Sets the status of the text stream to the status given.
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T * ptr(const T &t)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ padChar()

QChar QTextStream::padChar ( ) const

Returns the current pad character.

See also
setPadChar(), setFieldWidth()

Definition at line 1447 of file qtextstream.cpp.

1448 {
1449  Q_D(const QTextStream);
1450  return d->padChar;
1451 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ pos()

qint64 QTextStream::pos ( ) const

Returns the device position corresponding to the current position of the stream, or -1 if an error occurs (e.

Since
4.2

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.

See also
seek()

Definition at line 1251 of file qtextstream.cpp.

Referenced by setCodec().

1252 {
1253  Q_D(const QTextStream);
1254  if (d->device) {
1255  // Cutoff
1256  if (d->readBuffer.isEmpty())
1257  return d->device->pos();
1258  if (d->device->isSequential())
1259  return 0;
1260 
1261  // Seek the device
1262  if (!d->device->seek(d->readBufferStartDevicePos))
1263  return qint64(-1);
1264 
1265  // Reset the read buffer
1266  QTextStreamPrivate *thatd = const_cast<QTextStreamPrivate *>(d);
1267  thatd->readBuffer.clear();
1268 
1269 #ifndef QT_NO_TEXTCODEC
1271  if (d->readBufferStartDevicePos == 0)
1272  thatd->autoDetectUnicode = true;
1273 #endif
1274 
1275  // Rewind the device to get to the current position Ensure that
1276  // readBufferOffset is unaffected by fillReadBuffer()
1277  int oldReadBufferOffset = d->readBufferOffset + d->readConverterSavedStateOffset;
1278  while (d->readBuffer.size() < oldReadBufferOffset) {
1279  if (!thatd->fillReadBuffer(1))
1280  return qint64(-1);
1281  }
1282  thatd->readBufferOffset = oldReadBufferOffset;
1283  thatd->readConverterSavedStateOffset = 0;
1284 
1285  // Return the device position.
1286  return d->device->pos();
1287  }
1288 
1289  if (d->string)
1290  return d->stringOffset;
1291 
1292  qWarning("QTextStream::pos: no device");
1293  return qint64(-1);
1294 }
double d
Definition: qnumeric_p.h:62
bool fillReadBuffer(qint64 maxBytes=-1)
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
__int64 qint64
Definition: qglobal.h:942
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
void restoreToSavedConverterState()

◆ read()

QString QTextStream::read ( qint64  maxlen)

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

Since
4.1
See also
readAll(), readLine(), QIODevice::read()

Definition at line 1718 of file qtextstream.cpp.

1719 {
1720  Q_D(QTextStream);
1722 
1723  if (maxlen <= 0)
1724  return QString::fromLatin1(""); // empty, not null
1725 
1726  return d->read(int(maxlen));
1727 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ readAll()

QString QTextStream::readAll ( )

Reads the entire content of the stream, and returns it as a QString.

Avoid this function when working on large files, as it will consume a significant amount of memory.

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

See also
readLine()

Definition at line 1666 of file qtextstream.cpp.

Referenced by QScriptEngine::importExtension(), QCss::Parser::init(), QScriptDebuggerConsolePrivate::loadScriptedCommands(), operator<<(), and QDeclarativeScriptParser::parse().

1667 {
1668  Q_D(QTextStream);
1670 
1671  return d->read(INT_MAX);
1672 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
#define INT_MAX

◆ readLine()

QString QTextStream::readLine ( qint64  maxlen = 0)

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(), QIODevice::readLine()

Definition at line 1692 of file qtextstream.cpp.

Referenced by QMacPasteboardMimeVCard::convertFromMime(), getLocations(), QGtkStylePrivate::getThemeName(), getVariables(), launchWebBrowser(), QSplitter::operator>>(), QDeclarativeDirParser::parse(), qt_parseQconfig(), readConf(), readSourceFile(), and trimmed().

1693 {
1694  Q_D(QTextStream);
1696 
1697  const QChar *readPtr;
1698  int length;
1699  if (!d->scan(&readPtr, &length, int(maxlen), QTextStreamPrivate::EndOfLine))
1700  return QString();
1701 
1702  QString tmp = QString(readPtr, length);
1703  d->consumeLastToken();
1704  return tmp;
1705 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ realNumberNotation()

QTextStream::RealNumberNotation QTextStream::realNumberNotation ( ) const

Returns the current real number notation.

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

Definition at line 1554 of file qtextstream.cpp.

Referenced by operator<<().

1555 {
1556  Q_D(const QTextStream);
1557  return d->realNumberNotation;
1558 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ realNumberPrecision()

int QTextStream::realNumberPrecision ( ) const

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

See also
setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase()

Definition at line 1586 of file qtextstream.cpp.

1587 {
1588  Q_D(const QTextStream);
1589  return d->realNumberPrecision;
1590 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ reset()

void QTextStream::reset ( )

Resets QTextStream's formatting options, bringing it back to its original constructed state.

The device, string and any buffered data is left untouched.

Definition at line 1175 of file qtextstream.cpp.

Referenced by reset().

1176 {
1177  Q_D(QTextStream);
1178 
1179  d->realNumberPrecision = 6;
1180  d->integerBase = 0;
1181  d->fieldWidth = 0;
1182  d->padChar = QLatin1Char(' ');
1183  d->fieldAlignment = QTextStream::AlignRight;
1184  d->realNumberNotation = QTextStream::SmartNotation;
1185  d->numberFlags = 0;
1186 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ resetStatus()

void QTextStream::resetStatus ( )

Resets the status of the text stream.

Since
4.1
See also
QTextStream::Status, status(), setStatus()

Definition at line 1614 of file qtextstream.cpp.

1615 {
1616  Q_D(QTextStream);
1617  d->status = Ok;
1618 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ seek()

bool QTextStream::seek ( qint64  pos)

Seeks to the position pos in the device.

Returns true on success; otherwise returns false.

Definition at line 1203 of file qtextstream.cpp.

Referenced by setCodec().

1204 {
1205  Q_D(QTextStream);
1206  d->lastTokenSize = 0;
1207 
1208  if (d->device) {
1209  // Empty the write buffer
1210  d->flushWriteBuffer();
1211  if (!d->device->seek(pos))
1212  return false;
1213  d->resetReadBuffer();
1214 
1215 #ifndef QT_NO_TEXTCODEC
1216  // Reset the codec converter states.
1217  resetCodecConverterStateHelper(&d->readConverterState);
1218  resetCodecConverterStateHelper(&d->writeConverterState);
1219  delete d->readConverterSavedState;
1220  d->readConverterSavedState = 0;
1221  d->writeConverterState.flags |= QTextCodec::IgnoreHeader;
1222 #endif
1223  return true;
1224  }
1225 
1226  // string
1227  if (d->string && pos <= d->string->size()) {
1228  d->stringOffset = int(pos);
1229  return true;
1230  }
1231  return false;
1232 }
QString * string() const
Returns the current string assigned to the QTextStream, or 0 if no string has been assigned...
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static void resetCodecConverterStateHelper(QTextCodec::ConverterState *state)
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
qint64 pos() const
Returns the device position corresponding to the current position of the stream, or -1 if an error oc...

◆ setAutoDetectUnicode()

void QTextStream::setAutoDetectUnicode ( bool  enabled)

If enabled is true, QTextStream will attempt to detect Unicode encoding by peeking into the stream data to see if it can find the UTF-16 or UTF-32 BOM (Byte Order Mark).

If this mark is found, QTextStream will replace the current codec with the UTF codec.

This function can be used together with setCodec(). It is common to set the codec to UTF-8, and then enable UTF-16 detection.

See also
autoDetectUnicode(), setCodec()

Definition at line 3203 of file qtextstream.cpp.

3204 {
3205  Q_D(QTextStream);
3206  d->autoDetectUnicode = enabled;
3207 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
#define enabled

◆ setCodec() [1/2]

void QTextStream::setCodec ( QTextCodec codec)

Sets the codec for this stream to codec.

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

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

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(), setLocale()

Definition at line 3148 of file qtextstream.cpp.

Referenced by locale(), operator<<(), QDeclarativeScriptParser::parse(), QDomDocumentPrivate::saveDocument(), setCodec(), and QTextDocumentWriter::write().

3149 {
3150  Q_D(QTextStream);
3151  qint64 seekPos = -1;
3152  if (!d->readBuffer.isEmpty()) {
3153  if (!d->device->isSequential()) {
3154  seekPos = pos();
3155  }
3156  }
3157  d->codec = codec;
3158  if (seekPos >=0 && !d->readBuffer.isEmpty())
3159  seek(seekPos);
3160 }
double d
Definition: qnumeric_p.h:62
bool seek(qint64 pos)
Seeks to the position pos in the device.
#define Q_D(Class)
Definition: qglobal.h:2482
QTextCodec * codec() const
Returns the codec that is current assigned to the stream.
__int64 qint64
Definition: qglobal.h:942
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
qint64 pos() const
Returns the device position corresponding to the current position of the stream, or -1 if an error oc...

◆ setCodec() [2/2]

void QTextStream::setCodec ( const char *  codecName)

Sets the codec for this stream to the QTextCodec for the encoding specified by codecName.

Common values for codecName include "ISO 8859-1", "UTF-8", and "UTF-16". If the encoding isn't recognized, nothing happens.

Example:

QTextStream out(&file);
out.setCodec("UTF-8");
See also
QTextCodec::codecForName(), setLocale()

Definition at line 3174 of file qtextstream.cpp.

3175 {
3177  if (codec)
3178  setCodec(codec);
3179 }
void setCodec(QTextCodec *codec)
Sets the codec for this stream to codec.
QTextCodec * codec() const
Returns the codec that is current assigned to the stream.
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62

◆ setDevice()

void QTextStream::setDevice ( QIODevice device)

Sets the current device to device.

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

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

Definition at line 1325 of file qtextstream.cpp.

Referenced by DumpIDL().

1326 {
1327  Q_D(QTextStream);
1328  flush();
1329  if (d->deleteDevice) {
1330 #ifndef QT_NO_QOBJECT
1331  d->deviceClosedNotifier.disconnect();
1332 #endif
1333  delete d->device;
1334  d->deleteDevice = false;
1335  }
1336 
1337  d->reset();
1338  d->status = Ok;
1339  d->device = device;
1340  d->resetReadBuffer();
1341 #ifndef QT_NO_QOBJECT
1342  d->deviceClosedNotifier.setupDevice(this, d->device);
1343 #endif
1344 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QIODevice * device() const
Returns the current device associated with the QTextStream, or 0 if no device has been assigned...
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
void flush()
Flushes any buffered data waiting to be written to the device.

◆ setFieldAlignment()

void QTextStream::setFieldAlignment ( FieldAlignment  mode)

Sets the field alignment to mode.

When used together with setFieldWidth(), this function allows you to generate formatted output with text aligned to the left, to the right or center aligned.

See also
fieldAlignment(), setFieldWidth()

Definition at line 1404 of file qtextstream.cpp.

Referenced by center(), left(), locale(), and right().

1405 {
1406  Q_D(QTextStream);
1407  d->fieldAlignment = mode;
1408 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setFieldWidth()

void QTextStream::setFieldWidth ( int  width)

Sets the current field width to width.

If width is 0 (the default), the field width is equal to the length of the generated text.

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(), setPadChar()

Definition at line 1465 of file qtextstream.cpp.

Referenced by qSetFieldWidth().

1466 {
1467  Q_D(QTextStream);
1468  d->fieldWidth = width;
1469 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setGenerateByteOrderMark()

void QTextStream::setGenerateByteOrderMark ( bool  generate)

If generate is true and a UTF codec is used, QTextStream will insert the BOM (Byte Order Mark) before any data has been written to the device.

If generate is false, no BOM will be inserted. This function must be called before any data is written. Otherwise, it does nothing.

See also
generateByteOrderMark(), bom()

Definition at line 3229 of file qtextstream.cpp.

Referenced by bom().

3230 {
3231  Q_D(QTextStream);
3232  if (d->writeBuffer.isEmpty()) {
3233  if (generate)
3234  d->writeConverterState.flags &= ~QTextCodec::IgnoreHeader;
3235  else
3236  d->writeConverterState.flags |= QTextCodec::IgnoreHeader;
3237  }
3238 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62

◆ setIntegerBase()

void QTextStream::setIntegerBase ( int  base)

Sets the base of integers to base, both for reading and for generating numbers.

base can be either 2 (binary), 8 (octal), 10 (decimal) or 16 (hexadecimal). If base is 0, QTextStream will attempt to detect the base by inspecting the data on the stream. When generating numbers, QTextStream assumes base is 10 unless the base has been set explicitly.

See also
integerBase(), QString::number(), setNumberFlags()

Definition at line 1517 of file qtextstream.cpp.

Referenced by bin(), dec(), hex(), locale(), and oct().

1518 {
1519  Q_D(QTextStream);
1520  d->integerBase = base;
1521 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static const uint base
Definition: qurl.cpp:268
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setLocale()

void QTextStream::setLocale ( const QLocale locale)

Sets the locale for this stream to locale.

Since
4.5

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.

See also
locale()

Definition at line 3269 of file qtextstream.cpp.

3270 {
3271  Q_D(QTextStream);
3272  d->locale = locale;
3273 }
double d
Definition: qnumeric_p.h:62
QLocale locale() const
Returns the locale for this stream.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setNumberFlags()

void QTextStream::setNumberFlags ( NumberFlags  flags)

Sets the current number flags to flags.

flags is a set of flags from the NumberFlag enum, and describes options for formatting generated code (e.g., whether or not to always write the base or sign of a number).

See also
numberFlags(), setIntegerBase(), setRealNumberNotation()

Definition at line 1490 of file qtextstream.cpp.

Referenced by forcepoint(), forcesign(), locale(), lowercasebase(), lowercasedigits(), noforcepoint(), noforcesign(), noshowbase(), showbase(), uppercasebase(), and uppercasedigits().

1491 {
1492  Q_D(QTextStream);
1493  d->numberFlags = flags;
1494 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setPadChar()

void QTextStream::setPadChar ( QChar  ch)

Sets the pad character to ch.

The default value is the ASCII space character (' '), or QChar(0x20). This character is used to fill in the space in fields when generating text.

Example:

QTextStream out(&s);
out.setFieldWidth(10);
out.setFieldAlignment(QTextStream::AlignCenter);
out.setPadChar('-');
out << "Qt" << "rocks!";

The string s contains:

----Qt------rocks!--
See also
padChar(), setFieldWidth()

Definition at line 1436 of file qtextstream.cpp.

Referenced by qSetPadChar().

1437 {
1438  Q_D(QTextStream);
1439  d->padChar = ch;
1440 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setRealNumberNotation()

void QTextStream::setRealNumberNotation ( RealNumberNotation  notation)

Sets the real number notation to notation (SmartNotation, FixedNotation, ScientificNotation).

When reading and generating numbers, QTextStream uses this value to detect the formatting of real numbers.

See also
realNumberNotation(), setRealNumberPrecision(), setNumberFlags(), setIntegerBase()

Definition at line 1543 of file qtextstream.cpp.

Referenced by fixed(), locale(), and scientific().

1544 {
1545  Q_D(QTextStream);
1546  d->realNumberNotation = notation;
1547 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setRealNumberPrecision()

void QTextStream::setRealNumberPrecision ( int  precision)

Sets the precision of real numbers to precision.

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

The precision cannot be a negative value. The default value is 6.

See also
realNumberPrecision(), setRealNumberNotation()

Definition at line 1569 of file qtextstream.cpp.

Referenced by qSetRealNumberPrecision().

1570 {
1571  Q_D(QTextStream);
1572  if (precision < 0) {
1573  qWarning("QTextStream::setRealNumberPrecision: Invalid precision (%d)", precision);
1574  d->realNumberPrecision = 6;
1575  return;
1576  }
1577  d->realNumberPrecision = precision;
1578 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setStatus()

void QTextStream::setStatus ( Status  status)

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

Since
4.1

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

See also
Status status() resetStatus()

Definition at line 1633 of file qtextstream.cpp.

Referenced by operator>>().

1634 {
1635  Q_D(QTextStream);
1636  if (d->status == Ok)
1637  d->status = status;
1638 }
double d
Definition: qnumeric_p.h:62
Status status() const
Returns the status of the text stream.
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ setString()

void QTextStream::setString ( QString string,
QIODevice::OpenMode  openMode = QIODevice::ReadWrite 
)

Sets the current string to string, using the given openMode.

If a device has already been assigned, QTextStream will call flush() before replacing it.

See also
string(), setDevice()

Definition at line 1365 of file qtextstream.cpp.

1366 {
1367  Q_D(QTextStream);
1368  flush();
1369  if (d->deleteDevice) {
1370 #ifndef QT_NO_QOBJECT
1371  d->deviceClosedNotifier.disconnect();
1372  d->device->blockSignals(true);
1373 #endif
1374  delete d->device;
1375  d->deleteDevice = false;
1376  }
1377 
1378  d->reset();
1379  d->status = Ok;
1380  d->string = string;
1381  d->stringOpenMode = openMode;
1382 }
QString * string() const
Returns the current string assigned to the QTextStream, or 0 if no string has been assigned...
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
void flush()
Flushes any buffered data waiting to be written to the device.

◆ skipWhiteSpace()

void QTextStream::skipWhiteSpace ( )

Reads and discards whitespace from the stream until either a non-space character is detected, or until atEnd() returns true.

This function is useful when reading a stream character by character.

Whitespace characters are all characters for which QChar::isSpace() returns true.

See also
operator>>()

Definition at line 1307 of file qtextstream.cpp.

Referenced by ws().

1308 {
1309  Q_D(QTextStream);
1311  d->scan(0, 0, 0, QTextStreamPrivate::NotSpace);
1312  d->consumeLastToken();
1313 }
double d
Definition: qnumeric_p.h:62
#define CHECK_VALID_STREAM(x)
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_VOID
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ status()

QTextStream::Status QTextStream::status ( ) const

Returns the status of the text stream.

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

Definition at line 1598 of file qtextstream.cpp.

Referenced by QWSCalibratedMouseHandler::readCalibration(), setStatus(), and write_xpm_image().

1599 {
1600  Q_D(const QTextStream);
1601  return d->status;
1602 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

◆ string()

QString * QTextStream::string ( ) const

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

See also
setString(), device()

Definition at line 1390 of file qtextstream.cpp.

Referenced by QTextStream(), seek(), and setString().

1391 {
1392  Q_D(const QTextStream);
1393  return d->string;
1394 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73

Friends and Related Functions

◆ bin()

QTextStream & bin ( QTextStream stream)
related

Calls QTextStream::setIntegerBase(2) on stream and returns stream.

See also
oct(), dec(), hex(), {QTextStream manipulators}

Definition at line 2702 of file qtextstream.cpp.

Referenced by locale().

2703 {
2704  stream.setIntegerBase(2);
2705  return stream;
2706 }
static FILE * stream
void setIntegerBase(int base)
Sets the base of integers to base, both for reading and for generating numbers.

◆ bom()

QTextStream & bom ( QTextStream stream)
related

Toggles insertion of the Byte Order Mark on stream when QTextStream is used with a UTF codec.

See also
QTextStream::setGenerateByteOrderMark(), {QTextStream manipulators}

Definition at line 3127 of file qtextstream.cpp.

3128 {
3129  stream.setGenerateByteOrderMark(true);
3130  return stream;
3131 }
static FILE * stream
void setGenerateByteOrderMark(bool generate)
If generate is true and a UTF codec is used, QTextStream will insert the BOM (Byte Order Mark) before...

◆ center()

QTextStream & center ( QTextStream stream)
related

Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.

See also
left(), right(), {QTextStream manipulators}

Definition at line 3009 of file qtextstream.cpp.

Referenced by QTriangulator< T >::ComplexToSimple::Event::operator<(), QRect::QRect(), and QSplashScreen::setPixmap().

3010 {
3012  return stream;
3013 }
static FILE * stream
void setFieldAlignment(FieldAlignment alignment)
Sets the field alignment to mode.

◆ dec()

QTextStream & dec ( QTextStream stream)
related

Calls QTextStream::setIntegerBase(10) on stream and returns stream.

See also
bin(), oct(), hex(), {QTextStream manipulators}

Definition at line 2736 of file qtextstream.cpp.

Referenced by locale().

2737 {
2738  stream.setIntegerBase(10);
2739  return stream;
2740 }
static FILE * stream
void setIntegerBase(int base)
Sets the base of integers to base, both for reading and for generating numbers.

◆ endl()

QTextStream & endl ( QTextStream stream)
related

Writes '
' to the stream and flushes the stream.

Equivalent to

stream << '\n' << flush;

Note: On Windows, all '
' characters are written as '
' if QTextStream's device or string is opened using the QIODevice::Text flag.

See also
flush(), reset(), {QTextStream manipulators}

Definition at line 3032 of file qtextstream.cpp.

Referenced by classIDL(), DumpIDL(), noegl(), and qax_generateDocumentation().

3033 {
3034  return stream << QLatin1Char('\n') << flush;
3035 }
void flush()
Flushes any buffered data waiting to be written to the device.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fixed()

QTextStream & fixed ( QTextStream stream)
related

Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream.

See also
scientific(), {QTextStream manipulators}

Definition at line 2941 of file qtextstream.cpp.

Referenced by addFontToDatabase(), and locale().

2942 {
2944  return stream;
2945 }
void setRealNumberNotation(RealNumberNotation notation)
Sets the real number notation to notation (SmartNotation, FixedNotation, ScientificNotation).
static FILE * stream

◆ flush()

QTextStream & flush ( QTextStream stream)
related

Calls QTextStream::flush() on stream and returns stream.

See also
endl(), reset(), {QTextStream manipulators}

Definition at line 3047 of file qtextstream.cpp.

Referenced by QDirectFBWindowSurface::paintDevice().

3048 {
3049  stream.flush();
3050  return stream;
3051 }
static FILE * stream
void flush()
Flushes any buffered data waiting to be written to the device.

◆ forcepoint()

QTextStream & forcepoint ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForcePoint) on stream and returns stream.

See also
noforcepoint(), forcesign(), showbase(), {QTextStream manipulators}

Definition at line 2805 of file qtextstream.cpp.

2806 {
2808  return stream;
2809 }
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ forcesign()

QTextStream & forcesign ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and returns stream.

See also
noforcesign(), forcepoint(), showbase(), {QTextStream manipulators}

Definition at line 2788 of file qtextstream.cpp.

2789 {
2791  return stream;
2792 }
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ hex()

QTextStream & hex ( QTextStream stream)
related

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(), {QTextStream manipulators}

Definition at line 2754 of file qtextstream.cpp.

Referenced by initWritingSystems(), locale(), and verifyTag().

2755 {
2756  stream.setIntegerBase(16);
2757  return stream;
2758 }
static FILE * stream
void setIntegerBase(int base)
Sets the base of integers to base, both for reading and for generating numbers.

◆ left()

QTextStream & left ( QTextStream stream)
related

Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream.

See also
right(), center(), {QTextStream manipulators}

Definition at line 2975 of file qtextstream.cpp.

Referenced by locale(), QRect::QRect(), and QWindowsMobileStyle::subControlRect().

2976 {
2978  return stream;
2979 }
static FILE * stream
void setFieldAlignment(FieldAlignment alignment)
Sets the field alignment to mode.

◆ lowercasebase()

QTextStream & lowercasebase ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseBase) on stream and returns stream.

See also
uppercasebase(), lowercasedigits(), {QTextStream manipulators}

Definition at line 2907 of file qtextstream.cpp.

2908 {
2910  return stream;
2911 }
virtual ~QTextStream()
Destroys the QTextStream.
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ lowercasedigits()

QTextStream & lowercasedigits ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::UppercaseDigits) on stream and returns stream.

See also
uppercasedigits(), lowercasebase(), {QTextStream manipulators}

Definition at line 2924 of file qtextstream.cpp.

2925 {
2927  return stream;
2928 }
virtual ~QTextStream()
Destroys the QTextStream.
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ noforcepoint()

QTextStream & noforcepoint ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForcePoint) on stream and returns stream.

See also
forcepoint(), noforcesign(), noshowbase(), {QTextStream manipulators}

Definition at line 2856 of file qtextstream.cpp.

2857 {
2859  return stream;
2860 }
virtual ~QTextStream()
Destroys the QTextStream.
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ noforcesign()

QTextStream & noforcesign ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and returns stream.

See also
forcesign(), noforcepoint(), noshowbase(), {QTextStream manipulators}

Definition at line 2839 of file qtextstream.cpp.

2840 {
2842  return stream;
2843 }
virtual ~QTextStream()
Destroys the QTextStream.
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ noshowbase()

QTextStream & noshowbase ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and returns stream.

See also
showbase(), noforcesign(), noforcepoint(), {QTextStream manipulators}

Definition at line 2822 of file qtextstream.cpp.

2823 {
2825  return stream;
2826 }
virtual ~QTextStream()
Destroys the QTextStream.
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ oct()

QTextStream & oct ( QTextStream stream)
related

Calls QTextStream::setIntegerBase(8) on stream and returns stream.

See also
bin(), dec(), hex(), {QTextStream manipulators}

Definition at line 2719 of file qtextstream.cpp.

Referenced by locale().

2720 {
2721  stream.setIntegerBase(8);
2722  return stream;
2723 }
static FILE * stream
void setIntegerBase(int base)
Sets the base of integers to base, both for reading and for generating numbers.

◆ qSetFieldWidth()

QTextStreamManipulator qSetFieldWidth ( int  width)
related

Equivalent to QTextStream::setFieldWidth(width).

Definition at line 329 of file qtextstream.h.

330 {
332  return QTextStreamManipulator(func,width);
333 }
void(QTextStream::* QTSMFI)(int)
Definition: qtextstream.h:271
void setFieldWidth(int width)
Sets the current field width to width.

◆ qSetPadChar()

QTextStreamManipulator qSetPadChar ( QChar  ch)
related

Equivalent to QTextStream::setPadChar(ch).

Definition at line 335 of file qtextstream.h.

336 {
338  return QTextStreamManipulator(func, ch);
339 }
void(QTextStream::* QTSMFC)(QChar)
Definition: qtextstream.h:272
void setPadChar(QChar ch)
Sets the pad character to ch.

◆ qSetRealNumberPrecision()

QTextStreamManipulator qSetRealNumberPrecision ( int  precision)
related

Equivalent to QTextStream::setRealNumberPrecision(precision).

Definition at line 341 of file qtextstream.h.

342 {
344  return QTextStreamManipulator(func, precision);
345 }
void(QTextStream::* QTSMFI)(int)
Definition: qtextstream.h:271
void setRealNumberPrecision(int precision)
Sets the precision of real numbers to precision.

◆ reset()

QTextStream & reset ( QTextStream stream)
related

Calls QTextStream::reset() on stream and returns stream.

See also
flush(), {QTextStream manipulators}

Definition at line 3063 of file qtextstream.cpp.

3064 {
3065  stream.reset();
3066  return stream;
3067 }
void reset()
Resets QTextStream&#39;s formatting options, bringing it back to its original constructed state...
static FILE * stream

◆ right()

QTextStream & right ( QTextStream stream)
related

Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream.

See also
left(), center(), {QTextStream manipulators}

Definition at line 2992 of file qtextstream.cpp.

Referenced by QPainterPath::computeBoundingRect(), locale(), and QRect::QRect().

2993 {
2995  return stream;
2996 }
static FILE * stream
void setFieldAlignment(FieldAlignment alignment)
Sets the field alignment to mode.

◆ scientific()

QTextStream & scientific ( QTextStream stream)
related

Calls QTextStream::setRealNumberNotation(QTextStream::ScientificNotation) on stream and returns stream.

See also
fixed(), {QTextStream manipulators}

Definition at line 2958 of file qtextstream.cpp.

Referenced by locale().

2959 {
2961  return stream;
2962 }
void setRealNumberNotation(RealNumberNotation notation)
Sets the real number notation to notation (SmartNotation, FixedNotation, ScientificNotation).
static FILE * stream

◆ showbase()

QTextStream & showbase ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and returns stream.

See also
noshowbase(), forcesign(), forcepoint(), {QTextStream manipulators}

Definition at line 2771 of file qtextstream.cpp.

Referenced by locale().

2772 {
2774  return stream;
2775 }
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ uppercasebase()

QTextStream & uppercasebase ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseBase) on stream and returns stream.

See also
lowercasebase(), uppercasedigits(), {QTextStream manipulators}

Definition at line 2873 of file qtextstream.cpp.

2874 {
2876  return stream;
2877 }
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ uppercasedigits()

QTextStream & uppercasedigits ( QTextStream stream)
related

Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::UppercaseDigits) on stream and returns stream.

See also
lowercasedigits(), uppercasebase(), {QTextStream manipulators}

Definition at line 2890 of file qtextstream.cpp.

2891 {
2893  return stream;
2894 }
static FILE * stream
void setNumberFlags(NumberFlags flags)
Sets the current number flags to flags.
NumberFlags numberFlags() const
Returns the current number flags.

◆ ws()

QTextStream & ws ( QTextStream stream)
related

Calls skipWhiteSpace() on stream and returns stream.

See also
{QTextStream manipulators}

Definition at line 3079 of file qtextstream.cpp.

3080 {
3081  stream.skipWhiteSpace();
3082  return stream;
3083 }
static FILE * stream
void skipWhiteSpace()
Reads and discards whitespace from the stream until either a non-space character is detected...

Properties

◆ d_ptr

QScopedPointer<QTextStreamPrivate> QTextStream::d_ptr
private

Definition at line 261 of file qtextstream.h.


The documentation for this class was generated from the following files: