[Qt-interest] Objective-C like message-passing
Peter Kümmel
syntheticpp at gmx.net
Tue Sep 15 23:05:05 CEST 2009
Ross Bencina wrote:
> Hi Peter
>
> I use QMetaObject::invokeMethod a little bit for this kind of thing.
> It's pretty easy to use once you realise that it doesn't use the same
> method signature syntax as connect():
> http://doc.trolltech.com/4.5/qmetaobject.html#invokeMethod
>
> I'm not sure what advantages/disadvantages your idea has over this
> though...
>
Hi Ross,
QMetaMeassage uses QMetaObject::invokeMethod with some more advanced C++ techniques to
drop the Q_ARG macros.
the code from the docs
QMetaObject::invokeMethod(pushButton, "animateClick", Qt::QueuedConnection); becomes
pushButton->take("animateClick", Qt::QueuedConnection)();
and
QString retVal;
QMetaObject::invokeMethod(obj, "compute", Qt::DirectConnection,
Q_RETURN_ARG(QString, retVal),
Q_ARG(QString, "sqrt"),
Q_ARG(int, 42),
Q_ARG(double, 9.7));
becomes
QString retVal = obj->take("compute").reply<QString>("sqrt", 42, 9.7);
I assume you see the advantage ;)
A disadvantaged is: each passed type must define QTypeInfo<T>::name().
Reading this I thought, why not adding takeQueued and takeDirekt?
Peter
> Ross.
>
More information about the Qt-interest-old
mailing list