How to perform communication between Threads and PySide Qt?

1

The graphical user interface window created in PySide runs normally following the normal program flow. The program's true python script runs on a Thread in parallel. But this thread script needs to send the logs to the QPlainTextEdit of the graphical user interface created in PySide. However, it does not accept receiving commands from threads, which causes the window to crash. Would you like to know how to make this communication simple?

    
asked by anonymous 17.07.2018 / 17:59

1 answer

0

I discovered how:

        # Classe de Sinais.
        class Sinais(QtCore.QObject):
            # Elementos.
            elemento1 = QtCore.Signal()
            elemento2 = QtCore.Signal()

            def __init__(self):
                QtCore.QObject.__init__(self)
        sinal = Sinais() # Instância da Classe Sinais.



        def a():
            print('Bom dia')
        def b():
            print('Boa Noite')

        sinal.elemento1.connect(a)
        sinal.elemento2.connect(b)



        def c():
            while True:
                time.sleep(1)
                sinal.elemento1.emit()

        tarefa_c = threading.Thread(target=c)
        tarefa_c.daemon = True
        tarefa_c.start()
    
19.07.2018 / 03:40