View Full Version : Is this a bad nono? Geting the return value from a slot.

19th November 2011, 13:17
as far as I know there is no way to emit a signal and retrieve the value returned by the matching connected slot (please correct me if I am wrong).
So, how big a crime is it if i pass a parameter as an "out_value" to the slot, and the slot writes its return value in that "out_value" pointer?

something like:

self.connect( self, SIGNAL("mysignal(param,param)"), self.myslot )

self.out_var = {}
emit( SIGNAL( "mysignal(param,param)"), paramval1,self.out_var ) // slot is now executed, and return value
// is written to self.out_var

return_value = self.out_var['return']

and myslot :

def myslot(self,param1,param2):

param2['return'] = param1+param2;

return param2;

19th November 2011, 14:04
Why would that be a crime if it makes sense...

The "only" problem is that if the application is based on a message passing asynchronous architecture, you may have a problem if you have (through that pointer) a new value appearing somewhere, but no signal to start dealing with it & to noticy the app about it. But there are many situations where it is absolutely ok and good design.

22nd November 2011, 10:37
and what if there's two slots connected to that signal?
IMHO that's a bad idea.

Wouldn't it be better instead of returning a value, emit a signal with a value and connect it to where you want?

And you can get return value from a slot using QMetaObject::invokeMethod() but it requires different approach than connecting signal to slot.

23rd November 2011, 00:34
Also dangerous if the sender and receiver are in separate threads.