QStringEncoder¶
The QStringEncoder
class provides a state-based encoder for text. More…
Synopsis¶
Functions¶
def
requiredSpace
(inputLength)
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(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)
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.
See also
- class PySide6.QtCore.QStringEncoder¶
PySide6.QtCore.QStringEncoder(encoding[, flags=QStringConverterBase.Flag.Default])
PySide6.QtCore.QStringEncoder(name[, flags=QStringConverterBase.Flag.Default])
- Parameters
flags –
Flags
name – str
encoding –
Encoding
Default constructs an encoder. The default encoder is not valid, and can’t be used for converting text.
- PySide6.QtCore.QStringEncoder.requiredSpace(inputLength)¶
- Parameters
inputLength –
qsizetype
- Return type
qsizetype
Returns the maximum amount of characters required to be able to process inputLength
decoded data.
See also
appendToBuffer()
© 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.