PyQt ProgressBar: Update progress from other threads

Categories: Python; Tagged with: ; @ May 14th, 2015 23:40

Issue 1: UI is no responding when the progress is running

Create new thread to perform the progress:

Issue 2: QThread: Destroyed while thread is still running

Try to keep a reference:

Issue 3: QWidget::repaint: Recursive repaint detected

Use single to update progress:


Example: UploadThread:

class UploadTaskQtThread(QtCore.QThread):
    tick = QtCore.pyqtSignal(int, name="upload_changed")

    def __init__(self, client, local_path, remote_path):
        self.client = client
        self.local_path = local_path
        self.remote_path = remote_path
    def on_progress(self, progress):
        self.tick.emit(progress * 100)
    def run(self):
        self.client.upload_file(self.local_path, self.remote_path, self.on_progress)


    def upload(self, local_file_path, remote_path):
        self.upload_thread = UploadTaskQtThread(client, local_file_path, remote_path)


// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.