【问题标题】:PySide & Python3: TypeError on QActionPySide 和 Python3:QAction 上的 TypeError
【发布时间】:2013-10-30 23:58:47
【问题描述】:

我很困惑。我在 Ubuntu 13.10 下使用 Python3 运行 PySide。 我无法完成测试套件出错的简单任务;我将问题缩小到两行:

from PySide.QtGui import QAction
a = QAction("Test")

就是这样。如果我直接在 /usr/bin/python3 解释器 (v3.3.2) 中运行这两行代码,它会对我大喊:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'PySide.QtGui.QAction' called with wrong argument types:
  PySide.QtGui.QAction(str)
Supported signatures:
  PySide.QtGui.QAction(PySide.QtCore.QObject)
  PySide.QtGui.QAction(PySide.QtGui.QIcon, unicode, PySide.QtCore.QObject)
  PySide.QtGui.QAction(unicode, PySide.QtCore.QObject)

我真的不知道这应该是什么意思。我认为 Python3 中的所有(str)字符串都是 unicode。 Q为什么 PySide 抱怨不是隐含的相同类型(str unicode)?

欢迎任何帮助,我在这里迷路了。

【问题讨论】:

    标签: python python-3.x pyside


    【解决方案1】:

    天哪,我又做了一次。发布到 stackoverflow 后 1 分钟,经过数小时令人沮丧的工作后,我得到了解决方案;-)

    解决方法很简单:与str-unicode转换无关。 QAction 至少需要一个文本参数(str、bytes、unicode...)和一个父级(一个 QObject 派生类)——我忘了​​,只要 None 就足够了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      相关资源
      最近更新 更多