[Qt-interest] Mapping signals based on parameter value

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Thu Oct 15 03:42:40 CEST 2009


Erel wrote:

> Hi folks,
> 
> I know that i can use QSignalMapper to call a slot with different 
> parameters based on connection. What i want to achieve is a little 
> different.
> 
> We are using plugins in our application and different plugins are 
> responsible for different types of objects. We are connecting 
> multiple 
> slots, each implemented in a different plugin, to one signal 
> emitted by 
> the main application. One of the parameters of the signal is 
> a QString 
> indicating the type of object associated with the signal. 
> Currently, we 
> are checking this parameter in the slots and proceed if the type is 
> handled by the plugin. This has a downside, every plugin does this 
> checking and i want to avoid this if possible.
> 
> I want to connect all slots to the same signal, and when the 
> signal is 
> emitted, only the appropriate slot is called depending on the 
> value of 
> the QString argument, kind of like a QSignalMapper but in a 
> different way.
> 
> Is there any built-in mechanism to do this? If not, any ideas 
> on how i 
> can achieve this?
> 
> Thank you in advance.
> 
> Best Regards.

Hi Erel, 

As long as the plugins are doing the test, there is nothing you can do in
the main app to help solve the problem, without changing the plugin
interfaces.  

I suggest either:

1) Change the existing slot interface to a normal method that returns
whether the plugin has handled the string.  Then call each plugin until you
get one that returns true.  That way you only call half of them on average.


2) Or better, add another interface to the plugins to return the string or
strings that they can handle, and hold these in a map in the main app when
the plugins are loaded.  Then later, lookup the map to work out which plugin
to call.  

Hope that helps,





More information about the Qt-interest-old mailing list