I am trying to create a PyQt5 application, where I have used certain labels for displaying status variables. To update them, I have implemented custom pyqtSignal
manually. However, on debugging I find that the value of GUI QLabel
have changed but the values don't get reflected on the main window.
Some answers suggested calling QApplication().processEvents()
occasionally. However, this instantaneously crashes the application and also freezes the application.
Here's a sample code (all required libraries are imported, it's just the part creating problem, the actual code is huge):
from multiprocessing import Process
def sub(signal):
i = 0
while (True):
if (i % 5 == 0):
signal.update(i)
class CustomSignal(QObject):
signal = pyqtSignal(int)
def update(value):
self.signal.emit(value)
class MainApp(QWidget):
def __init__(self):
super().__init__()
self.label = QLabel("0");
self.customSignal = CustomSignal()
self.subp = Process(target=sub, args=(customSignal,))
self.subp.start()
self.customSignal.signal.connect(self.updateValue)
def updateValue(self, value):
print("old value", self.label.text())
self.label.setText(str(value))
print("new value", self.label.text())
The output of the print
statements is as expected. However, the text in label does not change.
The update
function in CustomSignal
is called by some thread.
I've applied the same method to update progress bar which works fine.
Is there any other fix for this, other than processEvents()
?
The OS is Ubuntu 16.04.