WPF 类似 QT 信号和槽的值转换器吗?
将双信号连接到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,除了创建适配器 QObject 之外,没有这样的东西。 Qt 允许的参数传递最奇怪的颠覆是将带参数的信号连接到不带参数的槽(参数被忽略),并混合和匹配
Type
和const 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
andconst 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.