PyQt5 Signals and QObject slots do not have attribute errors

I am trying to find a way to update a GUI thread from a Python thread outside the main one. The PyQt5 docs on sourceforge have good instructions on how to do this. But I still can't get it to work.

Is there a good way to explain the following result of an interactive session? Should there be a way to call the emit method on these objects?

>>> from PyQt5.QtCore import QObject, pyqtSignal >>> obj = QObject() >>> sig = pyqtSignal() >>> obj.emit(sig) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'QObject' object has no attribute 'emit' 

and

 >>> obj.sig.emit() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'QObject' object has no attribute 'sig' 

and

 >>> obj.sig = pyqtSignal() >>> obj.sig.emit() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'emit' 
+7
user-interface pyqt5 qt-signals pyqt
source share
1 answer

The following words and codes are in the PyQt5 docs .

New signals should only be defined in subclasses of QObject. They must contain part of the class definition and cannot be dynamically added as class attributes after the class definition.

 from PyQt5.QtCore import QObject, pyqtSignal class Foo(QObject): # Define a new signal called 'trigger' that has no arguments. trigger = pyqtSignal() def connect_and_emit_trigger(self): # Connect the trigger signal to a slot. self.trigger.connect(self.handle_trigger) # Emit the signal. self.trigger.emit() def handle_trigger(self): # Show that the slot has been called. print "trigger signal received" 
+15
source share

All Articles