WPF 类似 QT 信号和槽的值转换器吗?

发布于 2024-11-03 19:45:29 字数 168 浏览 5 评论 0原文

将双信号连接到 QT 中的 QString 插槽的最佳方法是什么?由于这些信号和槽不兼容,因此无法进行直接连接。是否有类似于 WPF 数据绑定中使用的值转换器的机制来在 QT 中实现此目的?

我可以实现我自己的双槽,然后发出我自己的 QString 信号,但感觉简单的值转换需要做很多工作。还有其他方法吗?

What is the best way for connecting for example a double signal to a QString slot in QT? Since these signals and slots are incompatible, a direction connection is not possible. Is there any mechanism similar to the Value Converters used in WPF data binding for achieving this in QT?

I could implement my own double slot which then emits my own QString signal, but it just feels like a lot of work for a simple value conversion. Are there other ways?

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

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

发布评论

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

评论(1

梦萦几度 2024-11-10 19:45:29

不幸的是,除了创建适配器 QObject 之外,没有这样的东西。 Qt 允许的参数传递最奇怪的颠覆是将带参数的信号连接到不带参数的槽(参数被忽略),并混合和匹配 Typeconst Type& (我对此不是 100% 确定)。

不过,通过重新实现 qt_metacall 方法并使用不同的转换和信号/槽数量策略,您可以对适配器感到疯狂。与简单地创建双插槽相比,这是一项相当大(且有趣)的任务。

Other than creating an adapter QObject, there is no such thing, unfortunately. The weirdest subversion of argument passing Qt allows is to connect a signal with arguments to a slot without parameters (the arguments are ignored) and to mix and match Type and const Type& (I'm not 100% sure on this).

You can go crazy with the adapter though, by reimplementing the qt_metacall method and using different strategies for conversion and signal/slot arity. It's a considerably big (and fun) task if compared to simply creating a double slot.

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