[Qt-interest] How to use QObject::connect with QMetaMethoud
Sergey Vidyuk
vestnik at ngs.ru
Mon May 10 22:31:03 CEST 2010
Hello
I have two instances of QObject subclasses and two
instances of QMetaMethod. One meta method is signal in the
first object and another one is slot in the second one. I
want to connect this signal and slot but there is a
problem. QObject::connect() require to use SIGNAL() and
SLOT() macroses and they are adding additional number
character to the beginning of method signature. I haven't
found straight forward way to create such connection in
the Qt documentation but after reading macro definitions
in the corresponding header I've tried the following
simple test example:
-------
#include <cstdio>
#include <QtCore/QObject>
#include <QtCore/QTextStream>
#include <QtCore/QString>
#include <QtCore/QByteArray>
QByteArray signature() {
return "mySignal(int)";
}
int main() {
QTextStream out(stdout);
out << SIGNAL(mySignal(int)) << endl;
out << QString(SIGNAL(%1)).arg(signature().data()) <<
endl;
return 0;
}
-------
Both printed lines are identical and it looks like I can
use the following code in my application:
-------
QObject::connect(
obj1,
QString(SIGNAL(%1)).arg(signal->signature().data()),
obj2,
QString(SLOT(%1)).arg(slot->signature().data()) );
-------
But such code relies on undocumented Qt internals which
and
can be broken by future versions of the toolkit. Are there
any
reliable way to connect signal with slot using QMetaMethod
representation of them?
Kind regards
Sergey Vidyuk
More information about the Qt-interest-old
mailing list