我在pyqtSignal通过线程时遇到问题。 我得到以下错误:
AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'
在命令中:
^{pr2}$该程序基本上是一个用PyQt设计器设计的主窗口,通过线程调用一些不同的函数。 我想在主窗口代码中获取一些线程的完成信号(以便显示结果等)。下面是解释其体系结构的代码的一小部分。在
主代码:
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
#Some code...
self.Button.clicked.connect(self.launch_Calculation_clicked)
def launch_Calculation(self):
AE_Uni_thread = threading.Thread(target = CALCULS_AE.Calcul_AE_Uni, args = (arg1, arg2, arg3, arg4)) # Calculs_AE is a class defined in another file
CALCULS_AE.Uni_finished.connect(self.getFinishThread()) # Another function doing some other stuff with the thread's results
AE_Uni_thread.start()
类计算开始计算:
class CALCULS_AE(object):
#Signals
Uni_finished = QtCore.pyqtSignal()
Reb_finished = QtCore.pyqtSignal()
def __init__(self):
# Some Code
def Calculs_AE_Uni(self, arg1, arg2, arg3, arg4):
# Some Code launching the calculation
self.Uni_finished.emit()
PS:pyqtSignals在文档中指定的类级别上定义。在
谢谢!在
也许您需要从
QtCore
类继承?在您有以下错误:
必须创建一个Calculs对象:
self.calculs = Calculs()
如果要使用Python的本机
threading
,那么使用QThread
是没有意义的,有两个元素做了同样的操作,因此将QThread
更改为QObject
。将信号连接到函数时,必须传递函数的名称,而不是计算的函数。
不正确
对吧
^{pr2}$target
需要函数的名称,而不是计算的函数名。如果不打算修改
Calculs
类的构造函数,则不必实现它。代码:
相关问题 更多 >
编程相关推荐