January 11, 2012

wamo wamo
Lab Rat
21 posts

Send Signals to a specified receiver

 

Hello,

is it possible to send an signal to a specified receiver if multiple receiver are connected? How does the syntax look like then?

An alternative will be to create multiple functions and use 1:1 connections.

I am new to qt and have no idea what design would be better (or even possible)

thanks

6 replies

January 11, 2012

peppe peppe
Ant Farmer
1025 posts

This is totally breaking the whole concept of signals and slots. If you have to communicate something to a specific object, simply invoke a method on it.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

January 11, 2012

wamo wamo
Lab Rat
21 posts
peppe wrote:
This is totally breaking the whole concept of signals and slots. If you have to communicate something to a specific object, simply invoke a method on it.

Thanks for the answer.

I am thinking of a configuration class which can do following thinks:
1)Receive a configuration for a module which is stored in a map<key,map<string,string>>
key = modulename for configuration
map<string,string> = config and value pair

2) On request signal from a (specific module) for a value the config class looks if this value is set in the xml config file. If so then it send the required value to the (specific module) if not then the default value is set.

Multiple methods would cause a specialisation like

  1. void sendToTerminal( ... )
  2. void sendToEditor( ... )

and i would to keep the class abstract as possible to be able to use it in any program i write.

Maybe i should public inherit from the abstract config class to specialise it and put then the methods inside?

January 11, 2012

koahnig koahnig
Mad Scientist
2099 posts

As peppe already states sending a signal only to a specific slot is in contradiction to the signal-slot concept of Qt. However, you may include in the slot parameter list a parameter allowing the receiving object to decide whether it shall process or not.

January 11, 2012

wamo wamo
Lab Rat
21 posts
koahnig wrote:
However, you may include in the slot parameter list a parameter allowing the receiving object to decide whether it shall process or not.

Thanks for the reply

I already thought about such solution but that will cause a lot of overhead … i am still thinking of any better design idea.

The inheritance will work but i will still be dependent to include the header file from the config … i want to have a separate compilation of the dynamic libs to be possible.

January 11, 2012

koahnig koahnig
Mad Scientist
2099 posts

When overhead is your concern than basically you can call the methods directly in the different objects as suggested by Peppe.
With signals and slots you can send different signals which are relayed to the different objects because you can decide with connect where to send. However, this is at the day’s end not much different from direct calls when the signals are processed syncronously.

January 11, 2012

Volker Volker
Robot Herder
5428 posts

Some random ideas:

  • Add a QString parameter to signal in which you store the module name (key for the outer map)
  • In the class that creates the modules, use a QSignalMapper to distinguish the senders

How do you send back the data?

Why is that requestConfig() signal connected to multiple receivers at all and not only to your single config provider class?

 
  ‹‹ how can i get an unsorted qmap?      trying to render TextLine in itemdelegate , but can’t see it ››

You must log in to post a reply. Not a member yet? Register here!