Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. sending data to a different thread
QtWS25 Last Chance

sending data to a different thread

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 476 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.
  • I Offline
    I Offline
    Igor86
    wrote on last edited by
    #1

    Hi all,

    I am at the beginning of my learning curve, and trying to understand how to solve a problem i have.

    I'm having a main class. in this main class I have a instance of another class that runs on a different QThread.
    This code emits a signal that I can access from my main class (above) like this:

       def getImage(self):        
                self.thread = QThread()        
                self.worker = Worker()               
                self.worker.imagesignal.connect(self.setImage)
    
       def setImage(self, img, imgOriginal, classname = str, score = float):
                ... some more code here...
    
    class Worker(QObject):
        finished = pyqtSignal()
        imagesignal = pyqtSignal(numpy.ndarray, numpy.ndarray, str, float)
    
        def run(self):
            h = Harvester()
            ia = yoloRun.open_stream(h)
            model = yoloRun.loadNetwork()
            while 1:      
                im0, imgOr, classname, score = yoloRun.run(imageAcq=ia, model=model)
                self.imagesignal.emit(im0, imgOr, classname, score)
            self.finished.emit()
    

    now, what I would need to do, is to send a trigger back (simple bool variable) to the worker thread. (i want to add after the while1: an event.

    I tried to declare the signal in my main class like this:

        startCameraSignal = pyqtSignal(bool)    
        self.startCameraSignal.emit(True)
    

    but I don't know how to detect the signal from the instance of worker...

    Is this even the correct way of doing it?

    Thank you

    Best regards

    Igor

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

      Hi,

      It's usually done through a slot.

      One note: do not use while 1. Doing so you do not have any clean way to stop your loop.

      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