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. How to call QObject.receivers() and QObject.isSignalConnected() in the right way?
Qt 6.11 is out! See what's new in the release blog

How to call QObject.receivers() and QObject.isSignalConnected() in the right way?

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 1.0k Views 2 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.
  • S Offline
    S Offline
    StarterKit
    wrote on last edited by StarterKit
    #1

    Hi all,
    Could anyone please provide a working example of how to use either QObject.receivers() or QObject.isSignalConnected() in python code?

    I've found some examples written in C++ and some old topics for PyQt4... - maybe I'm stupid enough but I can't figure out how to do the same in python (I tried to play with QMetaObject and other things but without any sign of success. So I need help...)

    Pl45m4P 1 Reply Last reply
    0
    • S Offline
      S Offline
      StarterKit
      wrote on last edited by StarterKit
      #4

      The best option I found for isSignalConnected() is:

      m_header = header.metaObject()
      header.isSignalConnected(m_header.method(m_header.indexOfSignal("sectionDoubleClicked(int)")))
      

      It works, but... looks a bit strange for me...

      1 Reply Last reply
      0
      • S StarterKit

        Hi all,
        Could anyone please provide a working example of how to use either QObject.receivers() or QObject.isSignalConnected() in python code?

        I've found some examples written in C++ and some old topics for PyQt4... - maybe I'm stupid enough but I can't figure out how to do the same in python (I tried to play with QMetaObject and other things but without any sign of success. So I need help...)

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #2

        @StarterKit

        Just check the example given in the documentation

        valueChangedSignal = QMetaMethod.fromSignal(MyObject.valueChanged)
        if isSignalConnected(valueChangedSignal):
            data = QByteArray()
            data = get_the_value() # expensive operation
            valueChanged.emit(data)
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        S 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @StarterKit

          Just check the example given in the documentation

          valueChangedSignal = QMetaMethod.fromSignal(MyObject.valueChanged)
          if isSignalConnected(valueChangedSignal):
              data = QByteArray()
              data = get_the_value() # expensive operation
              valueChanged.emit(data)
          
          S Offline
          S Offline
          StarterKit
          wrote on last edited by StarterKit
          #3

          @Pl45m4 , I tried it. Have it worked for you?
          I have:
          from PySide6.QtCore import QMetaMethod
          signal = QMetaMethod.fromSignal(view_header.sectionDoubleClicked)
          and it fails with:
          AttributeError: type object 'PySide6.QtCore.QMetaMethod' has no attribute 'fromSignal'
          This is the reason for my question.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            StarterKit
            wrote on last edited by StarterKit
            #4

            The best option I found for isSignalConnected() is:

            m_header = header.metaObject()
            header.isSignalConnected(m_header.method(m_header.indexOfSignal("sectionDoubleClicked(int)")))
            

            It works, but... looks a bit strange for me...

            1 Reply Last reply
            0
            • S StarterKit has marked this topic as solved on

            • Login

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