pyqt QLabel not rendered while another thread update its text
<p>I have a GUI program built on PyQt5, which constantly receive messages. The GUI has a QLabel showing the number of messages received, and a QThread trying to receive messages and update counter in an infinite loop in the run(). Here is the code:</p>

<pre><code>class ReceiveThread(QtCore.QThread):
    def __init__(self, parent, dialog, config):
        super(BufRecvThread, self).__init__(parent)
        #here dialog is the QDialog which contains the QLabel showing the message counter
        self.dialog=dialog             
        self.toStop=False

    def run(self):
        bufRecvCnt=0
        while not self.toStop:
            recv_buff=sock.recvMessage()
            bufRecvCnt=bufRecvCnt+1
            #self.dialog.lbBufRecvCnt is the QLabel showing the message counter
            self.dialog.lbBufRecvCnt.setText(str(bufRecvCnt))
            QApplication.processEvents() #this statement has no effect
</code></pre>

<p>However, most of the time, I find that the QLabel in the GUI does NOT render the counter properly, say, the ReceiveThread has received 10000 messages and block at sock.recvMessage(), the QLabel still shows "500" until I manually resize the GUI causing the GUI to rerender.</p>

<p>I tried the suggestions of this thread <a href="https://stackoverflow.com/questions/12518855/pyqt-qtgraphicsview-does-not-get-updated-within-loop">pyqt QtGraphicsView does not get updated within loop</a>, and added QApplication.processEvents() into the loop, but still NOT work.</p>

<p>So, is it proper to <strong>directly update</strong> the GUI from another thread? <a href="https://stackoverflow.com/questions/13420931/pyqt-modify-gui-from-another-thread">PyQt - Modify GUI from another thread</a> suggests to emit signals. As I'm not familiar with signal &amp; slot, should I use a predefined signal of the QLabel, or May I define whatever signal as i need, as long as the corresponding slot will update the text of the QLabel with setText().</p>