The QStringEncoder class provides a state-based encoder for text. More

Inheritance diagram of PySide6.QtCore.QStringEncoder



Detailed Description

A text encoder converts text from Qt’s internal representation into an encoded text format using a specific encoding.

Converting a string from Unicode to the local encoding can be achieved using the following code:

string = "..."
fromUtf16 = QStringEncoder(QStringEncoder.Utf8)
encodedString = fromUtf16(encodedString)

The encoder remembers any state that is required between calls, so converting data received in chunks, for example, when receiving it over a network, is just as easy, by calling the encoder whenever new data is available:

fromUtf16 = QStringEncoder(QStringEncoder.Utf8)
encoded = QByteArray()
while new_data_available():
    chunk = get_new_data()
    encoded += fromUtf16(chunk)

The QStringEncoder object maintains state between chunks and therefore works correctly even if a UTF-16 surrogate character is split between chunks.

QStringEncoder objects can’t be copied because of their internal state, but can be moved.

class PySide6.QtCore.QStringEncoder

PySide6.QtCore.QStringEncoder(encoding[, flags=Flag.Default])

PySide6.QtCore.QStringEncoder(name[, flags=Flag.Default])

  • flagsFlags

  • name – str

  • encodingEncoding

Default constructs an encoder. The default encoder is not valid, and can’t be used for converting text.



Return type


Returns the maximum amount of characters required to be able to process inputLength decoded data.

See also