如何使用QMetaMethod与QObject :: connect [英] How to use QMetaMethod with QObject::connect

查看:1451
本文介绍了如何使用QMetaMethod与QObject :: connect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个QObject子类的实例和两个QMetaMethod实例的信号在一个对象和另一个对象的插槽。

I have two instances of QObject subclasses and two QMetaMethod instances of signal in one of objects and slot in another object. I want to connect this signal and slot with each other.

我浏览了qobject.h文件,发现SIGNAL()和SLOT()宏只是添加1或2字符到方法签名的开头,所以它应该可以添加相同的字符到QMetaMethod :: signature()返回的字符串的开头,但这种方法取决于一些未记录的内部

I've looked through the qobject.h file and find that SIGNAL() and SLOT() macro are just add "1" or "2" character to the beginning of method signature so it looks like it should be possible to add the same character to the beginning of string returned by QMetaMethod::signature() but this approach depends on some undocumented internals of toolkit and may be broken at any time by a new version of Qt.

有没有人知道通过QMetaMethod反射表示来连接信号和槽的可靠方法?

Does anybody know reliable way to connect signals and slots through their QMetaMethod reflection representation?

编辑:
我在Qt问题跟踪器中创建了建议:
http://bugreports.qt-project.org/browse/QTBUG-10637
如果任何人也对此功能感兴趣可以投票给这张票。

Edited: I've created suggestion in Qt issue tracker: http://bugreports.qt-project.org/browse/QTBUG-10637 If anybody also interested in this feature you can vote for this ticket there.

推荐答案

看起来没有办法使它不依赖内部实现。如果我是您,我将向 Qt错误跟踪器提交功能请求,写入模拟当前行为SIGNAL / SLOT宏的代码,并添加单元测试,在SIGNAL / SLOT行为更改时失败。

It looks like there is no way to make it work without relying on internal implementation. If I were you, I'd submit feature request to Qt bug tracker, write a code that mimics current behavior SIGNAL/SLOT macros and add unit test that will fail when SIGNAL/SLOT behavior changes.

可能有一个更简单的解决方案,重新尝试解决:描述你想要做什么没有任何实现细节。

There might be a simpler solution to the problem you're trying to solve: describe what exactly are you trying to do without any implementation details.

这篇关于如何使用QMetaMethod与QObject :: connect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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