QTextEncoder Class

The QTextEncoder class provides a state-based encoder. \reentrant \ingroup i18n. More...

Header: #include <QTextEncoder>

Public Functions

QTextEncoder(const QTextCodec *codec)
QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags)
~QTextEncoder()
QByteArray fromUnicode(const QString &str)
QByteArray fromUnicode(QStringView str)
QByteArray fromUnicode(const QChar *uc, int len)
bool hasFailure() const

Detailed Description

\inmoduleQtCore5Compat

A text encoder converts text from Unicode into an encoded text format using a specific codec.

The encoder converts Unicode into another format, remembering any state that is required between calls.

See also QTextCodec::makeEncoder() and QTextDecoder.

Member Function Documentation

[explicit] QTextEncoder::QTextEncoder(const QTextCodec *codec)

Constructs a text encoder for the given codec.

[explicit] QTextEncoder::QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags)

Constructs a text encoder for the given codec and conversion flags.

\since4.7

[noexcept] QTextEncoder::~QTextEncoder()

Destroys the encoder.

QByteArray QTextEncoder::fromUnicode(const QString &str)

Converts the Unicode string str into an encoded QByteArray.

QByteArray QTextEncoder::fromUnicode(QStringView str)

This is an overloaded function.

\since5.10 Converts the Unicode string str into an encoded QByteArray.

QByteArray QTextEncoder::fromUnicode(const QChar *uc, int len)

This is an overloaded function.

Converts len characters (not bytes) from uc, and returns the result in a QByteArray.

bool QTextEncoder::hasFailure() const

\internal\since 4.5 Determines whether the encoder encountered a failure while decoding the input. If an error was encountered, the produced result is undefined, and gets converted as according to the conversion flags.