尝试发出整数信号时pyqt属性错误
pyqt attribute error when trying to emit integer signal
这可能是我某处的愚蠢错误;当我尝试实现此线程代码以更新 PyQt5 gui 的进度条级别时,出现以下错误:
Traceback (most recent call last):
File "threadtest.py", line 62, in <module>
app=MainWindow()
File "threadtest.py", line 35, in __init__
self.threadclass = ThreadClass()
File "threadtest.py", line 49, in __init__
self.getLevels()
File "threadtest.py", line 53, in getLevels
self.battery.emit()
AttributeError: 'int' object has no attribute 'emit'
[1:1:0100/000000.677780:ERROR:broker_posix.cc(43)] Invalid node channel message
密码是:
class MainWindow(QtWidgets.QMainWindow, gs.Ui_MainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent = parent)
self.setupUi(self)
self.threadclass = ThreadClass()
self.threadclass.start()
self.threadclass.battery.connect(self.updateLevels)
def updateLevels(self, val):
self.battery1bar.setValue(val)
class ThreadClass(QtCore.QThread):
battery = pyqtSignal(int)
def __init__(self, parent = None):
super(ThreadClass, self).__init__(parent = parent)
self.getLevels()
def getLevels(self):
self.battery=7
self.battery.emit()
gs.Ui_MainWindow.setupUi 是 qt 设计器自动生成的 ui。 getLevels 最终将动态检索电池电量。
您正在隐藏信号,因为您正在为其分配一个值:
self.battery = 7
您必须做的是将该值作为参数传递给 emit()
:
def getLevels(self):
self.battery.emit(7)
这可能是我某处的愚蠢错误;当我尝试实现此线程代码以更新 PyQt5 gui 的进度条级别时,出现以下错误:
Traceback (most recent call last):
File "threadtest.py", line 62, in <module>
app=MainWindow()
File "threadtest.py", line 35, in __init__
self.threadclass = ThreadClass()
File "threadtest.py", line 49, in __init__
self.getLevels()
File "threadtest.py", line 53, in getLevels
self.battery.emit()
AttributeError: 'int' object has no attribute 'emit'
[1:1:0100/000000.677780:ERROR:broker_posix.cc(43)] Invalid node channel message
密码是:
class MainWindow(QtWidgets.QMainWindow, gs.Ui_MainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent = parent)
self.setupUi(self)
self.threadclass = ThreadClass()
self.threadclass.start()
self.threadclass.battery.connect(self.updateLevels)
def updateLevels(self, val):
self.battery1bar.setValue(val)
class ThreadClass(QtCore.QThread):
battery = pyqtSignal(int)
def __init__(self, parent = None):
super(ThreadClass, self).__init__(parent = parent)
self.getLevels()
def getLevels(self):
self.battery=7
self.battery.emit()
gs.Ui_MainWindow.setupUi 是 qt 设计器自动生成的 ui。 getLevels 最终将动态检索电池电量。
您正在隐藏信号,因为您正在为其分配一个值:
self.battery = 7
您必须做的是将该值作为参数传递给 emit()
:
def getLevels(self):
self.battery.emit(7)