PyQt4.QtCore.pyqtSignal 对象没有属性“connect" [英] PyQt4.QtCore.pyqtSignal object has no attribute 'connect'
问题描述
我在创建的课程中遇到自定义信号问题.
I'm having issues with a custom signal in a class I made.
相关代码:
self.parse_triggered = QtCore.pyqtSignal()
def parseFile(self):
self.emit(self.parse_triggered)
这两个都属于类:RefreshWidget.在它的父类中,我有:
Both of those belong to the class: RefreshWidget. In its parent class I have:
self.refreshWidget.parse_triggered.connect(self.tabWidget.giveTabsData())
当我尝试运行程序时,出现错误:
When I try to run the program, I get the error:
AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'connect'
帮助?提前致谢.
推荐答案
我和你有同样的问题.
尝试移动
self.parse_triggered = QtCore.pyqtSignal()
在你的构造函数之外,但在你的类声明中.所以,而不是它看起来像这样:
out of your constructor but inside your class declaration. So instead of it looking like this:
class Worker(QtCore.QThread):
def __init__(self, parent = None):
super(Worker, self).__init__(parent)
self.parse_triggered = QtCore.pyqtSignal()
它应该是这样的:
class Worker(QtCore.QThread):
parse_triggered = QtCore.pyqtSignal()
def __init__(self, parent = None):
super(Worker, self).__init__(parent)
这可能根本不是您要找的,但它对我有用.无论如何,我切换回旧式信号,因为我还没有在新式信号中找到具有未定义数量或类型参数的方法.
This might not be at all what you are looking for, but it worked for me. I switched back to old-style signals anyways because I haven't found a way in new-style signals to have an undefined number or type of parameters.
这篇关于PyQt4.QtCore.pyqtSignal 对象没有属性“connect"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!