QStringDecoder¶
The QStringDecoder
class provides a state-based decoder for text. More…
Synopsis¶
Functions¶
def
appendToBuffer
(out, ba)def
requiredSpace
(inputLength)
Detailed Description¶
A text decoder converts text an encoded text format that uses a specific encoding into Qt’s internal representation.
Converting encoded data into a QString
can be achieved using the following code:
encodedString = "..." toUtf16 = QStringDecoder(QStringDecoder.Utf8) string = toUtf16(encodedString)
The decoder 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 decoder whenever new data is available:
toUtf16 = QStringDecoder(QStringDecoder.Utf8) string = QString() while new_data_available(): chunk = get_new_data() string += toUtf16(chunk)
The QStringDecoder
object maintains state between chunks and therefore works correctly even if chunks are split in the middle of a multi-byte character sequence.
QStringDecoder
objects can’t be copied because of their internal state, but can be moved.
See also
- class PySide6.QtCore.QStringDecoder¶
PySide6.QtCore.QStringDecoder(encoding[, flags=QStringConverterBase.Flag.Default])
PySide6.QtCore.QStringDecoder(name[, f=QStringConverterBase.Flag.Default])
- Parameters
flags –
Flags
f –
Flags
name – str
encoding –
Encoding
Default constructs an decoder. The default decoder is not valid, and can’t be used for converting text.
- PySide6.QtCore.QStringDecoder.appendToBuffer(out, ba)¶
- Parameters
out –
QChar
ba –
QByteArrayView
- Return type
QChar
Decodes the sequence of bytes viewed by in
and writes the decoded result into the buffer starting at out
. Returns a pointer to the end of data written.
out
needs to be large enough to be able to hold all the decoded data. Use requiredSpace
to determine the maximum size requirements to decode an encoded data buffer of in.size()
bytes.
See also
- PySide6.QtCore.QStringDecoder.requiredSpace(inputLength)¶
- Parameters
inputLength –
qsizetype
- Return type
qsizetype
Returns the maximum amount of UTF-16 code units required to be able to process inputLength
encoded data.
See also
© 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.