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. Issue PyQt5 QRunnable Signals
Forum Updated to NodeBB v4.3 + New Features

Issue PyQt5 QRunnable Signals

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.5k 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.
  • L Offline
    L Offline
    lvlanson
    wrote on last edited by
    #1

    For some reason the signals I emit from my QRunnable are not triggered in the parent class. I am not able to figure out what the problem is.

    The code reaches the "emitted" print statement in the qrunnable, but the pyqtslot is never been triggered.

    class ImageConc(qtc.QObject)
    
        def __init__(self):
            super().__init__()
            self.pool = qtc.QThreadPool.globalInstance()
    
        def run_thread(self, images: list):
            # some stuff happening
            runner = RunnerConcatenate(images, location, class_name)
            runner.signals.finished.connect(self.__on_job_done)
            self.pool.start(runner)
    
        @qtc.pyqtSlot()
        def __on_job_done(self):
            print("Done")
    
    class RunnerConcatenate(qtc.QRunnable):
    
        def __init__(self, sources: list, location: str, class_name: str):
            super().__init__()
            self.sources    = sources
            self.location   = location
            self.class_name = class_name
            self.signals    = ConcatSignal()
    
        @qtc.pyqtSlot()
        def run(self):
            # Some stuff happening
            self.signals.finished.emit()
            self.signals.errors.emit(error)
            print("emitted")
    
    
    class ConcatSignal(qtc.QObject):
        finished = qtc.pyqtSignal()
        errors   = qtc.pyqtSignal(list)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You design is overly complicated and wrong. Signals should be triggered from within the class that declares them. Why do you have a separate class containing only these two signals ?

      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
      • L Offline
        L Offline
        lvlanson
        wrote on last edited by
        #3

        Because I need to trigger the signal from an Object which is a QRunnable. From what I have read, QRunnable cannot have a signal object, since its not deriving from QObject.

        eyllanescE SGaistS 2 Replies Last reply
        0
        • L lvlanson

          Because I need to trigger the signal from an Object which is a QRunnable. From what I have read, QRunnable cannot have a signal object, since its not deriving from QObject.

          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

          @lvlanson please provide a minimal and reproducible example

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          1 Reply Last reply
          1
          • L Offline
            L Offline
            lvlanson
            wrote on last edited by
            #5

            This is super weird. If I run a minimal example it works flawlessly. But if I run it within my main application the signals are not being caught. I have no idea how to show a minimalistic example, I have no clue which point causes the problem.

            1 Reply Last reply
            0
            • L lvlanson

              Because I need to trigger the signal from an Object which is a QRunnable. From what I have read, QRunnable cannot have a signal object, since its not deriving from QObject.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @lvlanson said in Issue PyQt5 QRunnable Signals:

              Because I need to trigger the signal from an Object which is a QRunnable. From what I have read, QRunnable cannot have a signal object, since its not deriving from QObject.

              It does not mean you cannot derive from both QObject and QRunnable. You just have to respect the order, first QObject then QRunnable.

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

              eyllanescE 1 Reply Last reply
              0
              • SGaistS SGaist

                @lvlanson said in Issue PyQt5 QRunnable Signals:

                Because I need to trigger the signal from an Object which is a QRunnable. From what I have read, QRunnable cannot have a signal object, since its not deriving from QObject.

                It does not mean you cannot derive from both QObject and QRunnable. You just have to respect the order, first QObject then QRunnable.

                eyllanescE Offline
                eyllanescE Offline
                eyllanesc
                wrote on last edited by
                #7

                @SGaist In PyQt5 it is not possible

                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

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

                  Multiple inheritance not possible in Python ?

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

                  JonBJ 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Multiple inheritance not possible in Python ?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #9

                    @SGaist
                    https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#multiple-inheritance

                    Multiple Inheritance¶

                    It is not possible to define a new Python class that sub-classes from more than one Qt class. The exception is classes specifically intended to act as mixin classes such as those (like QQmlParserStatus) that implement Qt interfaces.

                    Dunno whether this affects/precludes the situation here, but it sounds like it does....

                    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