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(string)
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)
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¶
name – str
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.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.