PySide6.QtCore.QStringDecoder¶
- class QStringDecoder¶
- The - QStringDecoderclass provides a state-based decoder for text. More…- Synopsis¶- Methods¶- def - __init__()
- def - appendToBuffer()
- def - requiredSpace()
 - Static functions¶- def - decoderForHtml()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - A text decoder converts text an encoded text format that uses a specific encoding into Qt’s internal representation. - Converting encoded data into a - QStringcan 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 - QStringDecoderobject maintains state between chunks and therefore works correctly even if chunks are split in the middle of a multi-byte character sequence.- QStringDecoderobjects can’t be copied because of their internal state, but can be moved.- See also - __init__()¶
 - Default constructs an decoder. The default decoder is not valid, and can’t be used for converting text. - __init__(name[, f=QStringConverterBase.Flag.Default])
- Parameters:
- name – str 
- f – Combination of - Flag
 
 
 - __init__(encoding[, flags=QStringConverterBase.Flag.Default])
 - appendToBuffer(out, ba)¶
- Parameters:
- out – - QChar
- ba – - QByteArrayView
 
- Return type:
- QChar
 
 - Decodes the sequence of bytes viewed by - inand writes the decoded result into the buffer starting at- out. Returns a pointer to the end of data written.- outneeds to be large enough to be able to hold all the decoded data. Use- requiredSpaceto determine the maximum size requirements to decode an encoded data buffer of- in.size()bytes.- See also - static decoderForHtml(data)¶
- Parameters:
- data – - QByteArrayView
- Return type:
 
 - Tries to determine the encoding of the HTML in - databy looking at leading byte order marks or a charset specifier in the HTML meta tag and returns a- QStringDecodermatching the encoding. If the returned decoder is not valid, the encoding specified is not supported by- QStringConverter. If no encoding is detected, the method returns a decoder for Utf8.- See also - requiredSpace(inputLength)¶
- Parameters:
- inputLength – int 
- Return type:
- int 
 
 - Returns the maximum amount of UTF-16 code units required to be able to process - inputLengthencoded data.- See also