tags:

views:

80

answers:

2

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.

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.

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

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

A: 

If signature method is public in QMetaMethod then the result shouldn't be broken by trolls and it's safe to use it (documentation says nothing about "dangers" when using QMetaMethod::signature method). I think you can safely use it. Just to be sure, what version of Qt you are using right now ?

Kamil Klimek
not exactly correct. Since in QObject::connect documentation it's said that for signal and slot parameters SIGNAL() and SLOT() macro should be used I can't just use QMetaMethod::signature() function. Those macros output is differs from QMetaMethod::signature() output. The worst in this situation that those macros can't be used with strings calculated in runtime.
VestniK
And I'm using Qt 4.6.2 (latest version available in Ubuntu 10.04 official repository)
VestniK
A: 

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.

chalup
It looks like you are right. I'll try to ask in Qt-interest mailing list and if there will be no answer I'll fill a wishlist entry.
VestniK
I have some generated proxy classes which creates and sends RPC request when you call slot in them and emits signals when receiving some RPC request over the network (it's my own small opensource library http://qremotesignal.googlecode.com). I want to add function which can automatically connect all RPC shared signals and slot in proxy class with signals and slots of some target class which do real work in an application using this library.
VestniK