View Full Version : how can i know how many slots connected to a signal?
yj_yulin
30th November 2008, 04:09
if i can know this, i can reduce some object produce and even can drop the emit action.
thanks in advance.
aamer4yu
30th November 2008, 06:41
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
wysota
30th November 2008, 08:22
Emiting a signal is very cheap. It's a simple function call. If there are no slots connected, nothing more will happen.
jpn
30th November 2008, 10:11
See QObject::receivers().
ktk
30th November 2008, 10:25
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.
yj_yulin
30th November 2008, 13:59
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.
wysota
1st December 2008, 10:24
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.
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.