Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 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 Reply

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...