S
S
sharkyyy32020-07-11 20:08:54
Python
sharkyyy3, 2020-07-11 20:08:54

How to return a value from a QThread thread?

Actually, with the help of "return" it is not possible to return the value of a variable. How can I return the value "value" to the main thread?

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import (QGridLayout, QPushButton, QTextEdit, QInputDialog,
                             QApplication)
from PyQt5.QtCore import Qt, QThread

class proc_search(QThread):
    def __init__(self, parent = None):
        super().__init__()

    def run (self):
        value = ui.progressBar.value()
        while value < 100:
            value +=1
            ui.progressBar.setValue(value)
            time.sleep(0.1)

        return value
def get_users():
    but.start()


if __name__ == "__main__":

    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()

    but = proc_search()
    ui.pushButton.clicked.connect(get_users)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question