I can't get the example from the PySide6 documentation working on my system. I am running PySide-6.2 on Ubuntu.
toUtf16 = QStringDecoder(QStringConverter.Utf8)
toUtf16('test')
Result:
TypeError: 'PySide6.QtCore.QStringDecoder' object is not callable
It looks like a bug in PySide6. The returned object only has the inherited methods from QStringConverter , as can be seen by using dir
:
>>> dec = QtCore.QStringDecoder(QtCore.QStringConverter.Encoding.Utf16)
>>> for x in dir(dec):
... if x[0].islower(): print(x)
...
hasError
isValid
name
nameForEncoding
requiredSpace
resetState
state
So the decode methods are missing, and the TypeError
indicates that the ()
-operator overload is missing as well. The QStringEncoder
class has similar problems.
In PyQt6, everything works as expected:
>>> enc = QtCore.QStringEncoder(QtCore.QStringConverter.Encoding.Utf16)
>>> dec = QtCore.QStringDecoder(QtCore.QStringConverter.Encoding.Utf16)
>>> x = enc('text')
>>> x
PyQt6.QtCore.QByteArray(b't\x00e\x00x\x00t\x00')
>>> dec(x)
'text'
Of course, you don't really need to use these Qt classes, since the equivalent functionality already exists in Python.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.