gpt4 book ai didi

python - PySide: 'PySide.QtCore.Signal' 对象没有属性 'emit'

转载 作者:行者123 更新时间:2023-11-28 20:20:08 35 4
gpt4 key购买 nike

使用以下代码,在尝试发出信号时出现错误(“PySide.QtCore.Signal”对象没有属性“emit”):

#!/usr/bin/env python

from PySide import QtCore

class TestSignalClass(QtCore.QObject):
somesignal = QtCore.Signal()

def speak_me(self):
self.speak.emit()
def __init__(self):
try:
self.somesignal.emit()
except Exception as e:
print("__init__:")
print(e)

t = TestSignalClass()

我该怎么做才能解决这个问题?

最佳答案

这里的问题是,虽然该类正确地继承自QtCore.QObject,但它没有调用父类的构造函数。这个版本工作正常:

#!/usr/bin/env python

from PySide import QtCore

class TestSignalClass(QtCore.QObject):
somesignal = QtCore.Signal()

def speak_me(self):
self.speak.emit()
def __init__(self):
# Don't forget super(...)!
super(TestSignalClass, self).__init__()
try:
self.somesignal.emit()
except Exception as e:
print("__init__:")
print(e)

t = TestSignalClass()

关于python - PySide: 'PySide.QtCore.Signal' 对象没有属性 'emit',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32268225/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com