Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PySide Signals not being sent to Slot, from QThread object.

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

Scheduled Pinned Locked Moved Unsolved Language Bindings
2 Posts 2 Posters 717 Views
  • 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
    jscosta
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1

      • Login

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