PySide6.QtCore.QStringEncoder¶
- class QStringEncoder¶
- The - QStringEncoderclass provides a state-based encoder for text. More…- Synopsis¶- Methods¶- def - __init__()
- def - requiredSpace()
 - 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 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 - QStringEncoderobject maintains state between chunks and therefore works correctly even if a UTF-16 surrogate character is split between chunks.- QStringEncoderobjects can’t be copied because of their internal state, but can be moved.- See also - __init__()¶
 - Default constructs an encoder. The default encoder is not valid, and can’t be used for converting text. - __init__(name[, flags=QStringConverterBase.Flag.Default])
- Parameters:
- name – str 
- flags – Combination of - Flag
 
 
 - __init__(encoding[, flags=QStringConverterBase.Flag.Default])
 - requiredSpace(inputLength)¶
- Parameters:
- inputLength – int 
- Return type:
- int 
 
 - Returns the maximum amount of characters required to be able to process - inputLengthdecoded data.- See also - appendToBuffer()