多层 UI 小部件中的信号和插槽 [英] signals and slots in multilayered UI widgets

查看:28
本文介绍了多层 UI 小部件中的信号和插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有 follogin UI:

+---------------------------+|W1 +--------------+ |||W2 ||||+-----------+ |||||W3 |||||+-----------+ |||||||+--------------+ |+-------------------------+

W3 对 W1 中发出的某个信号(或更低级别,即 qApp)感兴趣.

想法是独立开发W3.但必须有人做信号/插槽连接.

如果我们希望 W3 不知道任何其他小部件,并且我们也不希望 W1 知道 W3,那么将 W1 中发出的信号连接到 W3 中的插槽的好做法/推荐方法是什么?

>

解决方案 1:将 W1 中的信号与 W2 中的信号连接(信号到信号技术),从而将 W2 中的信号连接到 W3 中的插槽.

解决方案 2:生成一个 qApp 信号并将其在 W2 中与 W3 中的插槽连接.

解决方案 3:生成一个 qApp 信号并让 W3 自己使用自己的插槽连接到它.

谢谢

解决方案

通常封闭小部件将小部件封装在其中并提供更高级别的接口.例如,如果 W3 包含多个需要根据某种状态启用/禁用的小部件,W3 将管理该状态,为其提供 API 并相应地启用/禁用小部件.所以通常不需要直接从W1到W3.

如果小部件彼此不了解(例如,b/c W1 是一个可以嵌入任何内容的通用容器小部件),那么组装 UI 的人,知道所有涉及的小部件,应该进行连接.

我不知道您所说的qApp 信号"是什么意思,但这听起来太像中央对象连接到所有东西,这当然也不是好的设计.

也许你想到了一个具体的例子?

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

解决方案

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?

这篇关于多层 UI 小部件中的信号和插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆