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. Can I Intercept client calls to connect a slot to my object's signal?
Forum Update on Monday, May 27th 2025

Can I Intercept client calls to connect a slot to my object's signal?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.2k 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.
  • JMO_GSJ Offline
    JMO_GSJ Offline
    JMO_GS
    wrote on last edited by
    #1

    I'm trying to figure out how I can intercept client calls to connect() to a signal exposed by my object. Emitting my signal requires some significant CPU work to be done by my object and only wish that to happen while some client has actually connected a slot to it so as to avoid wasting CPU otherwise.

    Is there a way I can make my object intercept client's connecting to / disconnecting from my signal?

    I've gone over the documentation and tried to step through the actual connect() code but I don't see a good spot.

    Thanks,

    -Joe

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! int QObject::receivers(const char *signal) const is exactly what you're looking for. See: http://doc.qt.io/qt-5/qobject.html#receivers

      1 Reply Last reply
      4
      • JMO_GSJ Offline
        JMO_GSJ Offline
        JMO_GS
        wrote on last edited by
        #3

        Hi Wieland. Thanks for answering.

        Unfortunately, unless I'm missing something, that function doesn't seem to be what I want. It lets me check the number of receivers but doesn't notify me when someone subscribes, is that right?

        I need to know right at the point someone connects to my signal that the connection has occurred. I need to be able to intercept the connect() calls themselves in some way or at least be told about it right after.

        (Maybe there is some virtual function I could override...?).

        When the first client connects, I start my expensive logic that periodically sends out signals.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #4

          I think connectNotify is what you want.

          1 Reply Last reply
          3
          • JMO_GSJ Offline
            JMO_GSJ Offline
            JMO_GS
            wrote on last edited by
            #5

            Perfect, that is it! I don't know how I could have missed that. I thought I'd scanned those docs up and down.

            Thank you

            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