简体   繁体   English

QStringDecoder 在 PySide6 中不可调用

[英]QStringDecoder not callable in PySide6

I can't get the example from the PySide6 documentation working on my system.我无法从在我的系统上运行的PySide6 文档中获取示例。 I am running PySide-6.2 on Ubuntu.我在 Ubuntu 上运行 PySide-6.2。

toUtf16 = QStringDecoder(QStringConverter.Utf8)
toUtf16('test')

Result:结果:

TypeError: 'PySide6.QtCore.QStringDecoder' object is not callable

It looks like a bug in PySide6.它看起来像 PySide6 中的一个错误。 The returned object only has the inherited methods from QStringConverter , as can be seen by using dir :返回的 object 仅具有从QStringConverter继承的方法,使用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.因此缺少decode 方法,并且TypeError指示() -operator 重载也丢失了。 The QStringEncoder class has similar problems. QStringEncoder class 也有类似的问题。

In PyQt6, everything works as expected:在 PyQt6 中,一切都按预期工作:

>>> 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.当然,您实际上并不需要使用这些 Qt 类,因为 Python 中已经存在等效功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM