Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal and slot connection from a thread!?
Forum Updated to NodeBB v4.3 + New Features

Signal and slot connection from a thread!?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 793 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jetmiri
    wrote on last edited by
    #1

    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):
        QtCore.QThread.__init__(self)
    
    
    def run(self):
         # here is a loop inside which the signals are transmitted
            while true
            {
               if a:
                   self.emit(QtCore.SIGNAL("button_left(QString)"))
               elif b:
                    self.emit(QtCore.SIGNAL("button_left(QString)"))
             }
    

    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)
    self.workThread.start()

    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/top_block.py", line 151, in _coerce_endpoint
    raise ValueError("unable to coerce endpoint")
    ValueError: unable to coerce endpoint

    Any suggestions would be appreciated!

    Regards

    [edit: added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved