Results 1 to 7 of 7

Thread: how can i know how many slots connected to a signal?

  1. #1
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default how can i know how many slots connected to a signal?

    if i can know this, i can reduce some object produce and even can drop the emit action.
    thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can i know how many slots connected to a signal?

    Wont it be better if you dont connect the slot to the signal.
    Not emitting the signal cud hamper your functionality,, after all why is a signal used ?
    hope am right

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can i know how many slots connected to a signal?

    Emiting a signal is very cheap. It's a simple function call. If there are no slots connected, nothing more will happen.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how can i know how many slots connected to a signal?

    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    yj_yulin (30th November 2008)

  6. #5
    Join Date
    May 2008
    Posts
    155
    Thanked 15 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how can i know how many slots connected to a signal?

    Quote Originally Posted by wysota View Post
    Emiting a signal is very cheap. It's a simple function call. If there are no slots connected, nothing more will happen.
    Well, it goes through MetaObject::activate() in any case. It will indeed return fairly early if nothing is connected, but it certainly is a bit more expensive than a single function call.

  7. #6
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can i know how many slots connected to a signal?

    Quote Originally Posted by wysota View Post
    Emiting a signal is very cheap. It's a simple function call. If there are no slots connected, nothing more will happen.
    signals:
    void a_happend(Tsomeobject * obj, int x, int y);

    yeah, though signal is cheap, the object need to create(Tsomeobject * obj) maybe not.

    and my situation also relate to the object management,thus if i can know there is no slots connected to the signal, it can reduce more work.

    thanks for all involved, and especially to jpn.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can i know how many slots connected to a signal?

    Quote Originally Posted by ktk View Post
    Well, it goes through MetaObject::activate() in any case. It will indeed return fairly early if nothing is connected, but it certainly is a bit more expensive than a single function call.
    I didn't say "single" Emiting a signal takes about 5-6 function calls but these are cheap compared to actual actions you take in the slot itself.

    Quote Originally Posted by yj_yulin View Post
    yeah, though signal is cheap, the object need to create(Tsomeobject * obj) maybe not.
    Yes, that's true. If you create an expensive object only to emit a signal then that's certainly a good idea to avoid the emission.

Similar Threads

  1. doubts in signal and slots
    By sar_van81 in forum Qt Programming
    Replies: 7
    Last Post: 2nd April 2007, 13:31
  2. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 11:10
  3. Emiting signal, which NOT connected to any slots
    By krivenok in forum Qt Programming
    Replies: 7
    Last Post: 27th February 2006, 17:32
  4. Problem with Signal and Slots
    By Kapil in forum Installation and Deployment
    Replies: 2
    Last Post: 10th February 2006, 09:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.