Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved PySide Signals not being sent to Slot, from QThread object.

    Language Bindings
    2
    2
    572
    Loading More Posts
    • 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
      jscosta last edited by

      Hello,

      I'm working with a multi-threading application, where a worker thread gets created, that emits a signal.
      After creating the thread, I connect the signal with an object slot, that will perform some action.

      The problem, is the object slot, is not called, can someone help to figure out what's wrong ?

      import time
      from PySide import QtCore
      from PySide.QtCore import Slot, Signal
      
      
      class Worker1(QtCore.QThread):
      
          task_done_signal = Signal(int)
      
          def __init__(self):
              super(Worker1, self).__init__()
              self._run = False
      
          def run(self):
              self._loop()
      
          def _loop(self):
              count = 0
              while self._run:
                  print("running")
                  count += 1
                  self.task_done_signal.emit(count)
      
          def start(self):
              self._run = True
              super(Worker1, self).start()
      
          def stop(self):
              self._run = False
      
      
      class Worker1Listener(QtCore.QObject):
          def __init__(self):
              super(Worker1Listener, self).__init__()
      
          @Slot()
          def print_task(self, val):
              print("listener: {}".format(val))
      
      
      def test_signals_and_threads():
      
          # create the thread
          worker = Worker1()
      
          # create the listener
          listener = Worker1Listener()
      
          # connect the thread signal with the slot
          worker.task_done_signal.connect(listener.print_task)
      
          worker.start()
      
          time.sleep(5)
      
          worker.stop()
      
          time.sleep(5)
      
      
      if __name__ == '__main__':
          test_signals_and_threads()
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        There's no event loop running at all. Therefore signals and slots won't be working.

        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 Reply Quote 1
        • First post
          Last post