Let's say we have the follogin UI:
+--------------------------+
|W1 +--------------+ |
| |W2 | |
| | +----------+ | |
| | |W3 | | |
| | +----------+ | |
| | | |
| +--------------+ |
+--------------------------+
W3 is interested in a certain signal emited in W1 (or a level below, i.e. qApp).
The idea is to develop W3 independently. But somebody has to do the signal/slot connection.
What would be a good practice/recommended way of connecting the signal emited in W1 into slot in W3 if we want W3 not to know about any other widget, and we don't want W1 to know about W3 either?
Solution 1: Connect signal in W1 with signal in W2 (signal to signal technique) and therefore connect signal in W2 to slot in W3.
Solution 2: Generate a qApp signal and connect it in W2 with slot in W3.
Solution 3: Generate a qApp signal and have W3 itself connect to it using its own slot.
Thanks
You might set name to widgets and then discover them anywhere:
or in the parent widget:
main.cpp
widget.cpp
widget.h
connect_by_name.cpp
connect_by_name.h
connect.pro
Usually the enclosing widget encapsulates the widgets inside it and provides a higher-level interface. E.g., if W3 contains several widgets that need to be enabled/disabled depending on some state, W3 would manage that state, provide API for it and enable/disable widgets accordingly. So usually there is no need to go directly from W1 to W3.
If the widgets don't know about each other (e.g. b/c W1 is a generic container widget that can embed anything), then the one who assembles the UI, knowing all involved widgets, should do the connection.
I don't know what you mean by "qApp signal", but that sounds too much like on central object being connected to everything, which of course isn't good design either.
Maybe you have a specific example you had in mind?
The approach we use here is that "the shell" makes the connections.
The shell is an object that knows about all the widgets involved. In this case, W1, W2, and W3. Usually it is the code that assembles the user interface.
If the shell doesn't know about W3 (because W3 is an implementation detail, for example) then W3's "owner" should make the connection and so on.