列出将所有 setter 函数作为 Qt 中的 SLOTS 的缺点(性能/维护等)?

发布于 2024-10-05 13:16:20 字数 204 浏览 0 评论 0原文

在 Qt 中将所有 setter 功能作为 SLOTS 是否有任何缺点(性能/维护等)?

我看到的一些缺点是,

1)不必要的 MOC 调用和编译期间创建的不必要的 moc 文件 2) 中断异常处理链,因为异常不是在信号槽连接中传递的 3)调试过程中不必要的复杂性,因为使用信号槽调试比直接方法调用更困难。

您能列出任何其他缺点吗(如果有的话)?

Is there any drawback (performance/maintenance etc.,) in having all setter functions as SLOTS in Qt?

Some of the disadvantages i see are,

1) Unnecessary call of MOC and Unnecessary moc files created during compile time
2) Break in the exception handling chain, since exceptions are not passed in signal-slot connection
3) Unnecessary complexity in debugging, since it is harder to debug with signal-slot thatn direct method call.

Can you list any other disadvantages (if any)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-10-12 13:16:20

如果您直接调用设置器,则可以避免您提到的大多数缺点。它将像任何其他正常调用一样运行。在这种情况下,唯一的缺点是编译时间更长,bin 大小更大。

如果你通过发出信号来调用所有的setter,那么:

1)更复杂的代码;因为您必须记住将所有信号连接到每组的所有插槽。

2) 性能影响较小。对于任何 GUI 应用程序来说,它都是可以忽略不计的;但它就在那里。

3) 确定性较低的代码。即,根据信号连接的方式,调用可以直接传递给被调用者,或者通过事件系统发送。除了您已经提到的之外,这进一步使调试变得复杂。

4)IDE问题。如果您不使用 QtCreator 或 KDevelop,IDE 可能无法理解特殊关键字(slot、signal、emit)。

除了(1)之外,所有这些问题都是次要的。但我说,不这样做的主要原因是它没有意义。如果没有必要,为什么要这样做?

软件工程应该是管理复杂性,而不是创造复杂性。

If you call the setters directly, you can avoid most of the drawbacks you mention. It will behave as any other normal call. The only drawback in that case would be the longer compiler time and bigger bin size.

If you call all your setters by emitting signals, then:

1) More complex code; since you have to remember to connect all your signals to all your slots for every set.

2) Small performance hit. It would be negligible for any GUI app; but its there.

3) Less deterministic code. I.e. depending on the way the signals are connected, the call might be passed directly to the callee, or sent through an event system. This further complicates debugging, besides what you've mentioned already.

4) IDE issues. If you are not using QtCreator or KDevelop, the IDE might not understand the special keywords (slot, signal, emit).

Except for (1), all these issues are minor. But the main reason for not doing this, I say, would be it doesn't make sense. Why do it if you don't have the need?

Software engineering should be about managing complexity, not creating it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文