Take the 2-minute tour ×

Hello I am trying to figure out how to get data from my worker class. I have server code running as a threaded process and I want to send some data from my server to the pyQT GUI

I have a variable in my gui code

    self.mytext = QTextEdit()

and in my server code I send the data to the GUI. Only problem is I don't know how to set up the Signals to do this right :-P

    self.emit(SIGNAL('mytext'), mytext.setText(msg))

Any ideas how to do this :-)


share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

First, have look at how Signals/Slots concept works. Original Qt documentation for is a good start. Then if you are working with PyQt 4.5+, try to use the new style signals and slots. They are more Pythonic.

Here is how a small example might work (omitting the obvious parts).

class myWorker(QtCore.QThread):
    # Register the signal as a class variable first
    mySignal = QtCore.pyqtSignal(QtCore.QString)

    # init and other stuff...

    def someFunction(self):
        # emit the signal with the parameter

class myWindow(QtGui.QMainWindow):
    def __init__(self):
        # usual init stuff and gui setup...
        self.mytext = QTextEdit()

        # worker
        self.worker = myWorker()
        # register signal to a slot
share|improve this answer
Thank you both for your help :-) –  ADE Oct 13 '11 at 15:51
add comment

You need to create the signal with the same signature as the slot you are targeting.

self.newText = QtCore.pyqtSignal(QtCore.QString)

Then connect it to the GUI 'setText' slot


And then you can emit it whenever you need to in the code:

self.newText.emit("My Text Here") 
share|improve this answer
add comment

Your Answer


