我试图在PyQt中第一次使用emit。我已经做了很多阅读和谷歌搜索,我确信我有这个正确,但我不断收到下面显示的错误。任何人都可以了解我做错了什么。
def checkRiskDescription(obj,form):
complete = True
if str(form.txtTitle.text()) == "":
complete = False
if len(str(form.txtOverview.toPlainText())) < 50:
complete = False
bar = form.tabRiskMain.tabBar()
if complete:
#Change Risk Description tab to Green
bar.setTabTextColor(0,QtGui.QColor(38, 169, 11, 255))
form.btnSave.enabeld = True
else:
#Change risk Description tab to Red
bar.setTabTextColor(0,QtGui.QColor(255, 0, 0, 255))
form.btnSave.enabled = False
QtGui.QWidget.emit(QtCore.SIGNAL("tabsUpdated"))
这是错误
File "D:\Development\python\PIF2\PIF\risk\risk.py", line 360, in checkRiskDescription
QtGui.QWidget.emit(QtCore.SIGNAL("tabsUpdated"))
TypeError: QObject.emit(SIGNAL(), ...): first argument of unbound method must have type 'QObject'
答案 0 :(得分:1)
我通常只是定义这样的信号
tabsUpdated = Qt.pyqtSignal()
然后通过
开火self.tabsUpdated.emit()
E.g
from PyQt4 import Qt
class SomeClass(Qt.QObject):
tabsUpdated = Qt.pyqtSignal()
def __init__(self):
Qt.QObject.__init__(self)
def something(self):
# bla bla loads of nice magic code bla bla
self.tabsUpdated.emit()
当然可以在你的python文件中全局定义信号。