I have a GUI with widgets that has multiple child widgets inside, as you can see in the image:
I want to communicate "Widget 2-2" with "Widget 1-1". I have different options, but I don't know which is better.
1. Propagate signal
My first idea was propagates the emit to Main Windows and then it propagates the action to the target widget:
- Widget 2-2 emits a signal
- Widget 2 catch the emit and emit anther signal
- Main Windows catch the emit and call a Widget 1 controller function
- Widget 1 controller function calls a Widget 1-1 controller function
- Widget 1-1 makes the action
Pros
- All the widgets only talks with its parents and children
Cons
- It can be a bit messy
2. Create a singleton class with all the signals
Another idea is to create the signals in a singleton class. Then the Widget 2-2 can emit this signals easily and Widget 1-1 can listen this signals easily too. The relative position of the widgets in the architecture does not care, everybody can emit and connect the signals.
Pros
- Emit and connect this signals is super easy. Everybody can do it.
Cons
- I feel that it is a super bad idea. Probably it will explode in the future, but I don't know why. I prefer to follow the best practices than solve my problem fast and easily (for the moment...)