Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

qt - signals and slots in multilayered UI widgets

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...