Signal and slot connection from a thread!?

  • Hi all,

    I am programming a GUI using pyqt4. I created a thread with an infinite loop inside which there are some signals which would be emitted if certain conditions are fulfilled. I am trying to connect these signals with button handles in the main class. The idea if like this:

    class WorkingThread(QtCore.QThread):

    def __init__(self):
    def run(self):
         # here is a loop inside which the signals are transmitted
            while true
               if a:
               elif b:

    class Mainclass(Qt.QWidget)

    def init(self)
    #other functions
    self.workThread = WorkingThread()
    self.connect( self.workThread, QtCore.SIGNAL("button_right(QString)"), self.handle_a2_right)
    self.connect(self.workThread,QtCore.SIGNAL("button_left(QString)"), self.handle_a2_left)

    def handle_a2_right
    #functions here

    def handle_a2_left
    #functions here

    When the program reach the connection line in the main class it gives this error:

    File "/usr/lib/python2.7/dist-packages/gnuradio/gr/", line 151, in _coerce_endpoint
    raise ValueError("unable to coerce endpoint")
    ValueError: unable to coerce endpoint

    Any suggestions would be appreciated!


    [edit: added missing coding tags @ SGaist]

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You have two design issues here.
    First: button_left(QString) and button_left(QString) are not members of WorkingThread.

    Second: emitting signals from the run function reimplementation doesn't behave like you might think it does. Please take a look at QThread's latest documentation to see how it should be done.

    Hope it helps

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.