qt - What's the QMetaCallEvent for and how to access its details? -


i have event filter , noticed when click expand/collapse tree branch qevent::metacall. thinking using roll own expand/collapse code, don't know how information, such index of item.

is there available metacall event type?

i found had asked same question on site, without answer, here: http://www.qtcentre.org/threads/37525-how-to-filter-qevent-metacall

what event typically used for?

the biggest question are: what trying do? qt class received events? far i'm concerned, you're trying things hard way, why bother?

the qmetacallevent event representing slot call whenever queued connection used invoke slot. might due signal firing connected slot, or due use qmetaobject::invoke or qmetaobject::invokemethod. queued connection bit important part! queued connections not used default, since have event queue management overhead, unless either of 2 conditions below holds true:

  1. you provide qt::queuedconnection argument qobject::connect or qmetaobject::invoke[method], or

  2. the receiving object's thread() different thread call originating.

the qmetacallevent event class carries information needed invoke slot. contains sender qobject , signal id (if call comes signal-slot connection), target slot identifier, , arguments needed passed slot.

thus, check if called slot 1 wish intercept, arguments passed it. example, if you're calling slot single int parameter, *reinterpret_cast<int*>(metacallevent->args()[1]) give value of integer. zero-th argument used return value, if any, parameters indexed base 1.

disclaimer since qmetacallevent class internal qt's implementation, you're making application's binary tied particular qt version in full (entire major.minor version) , lose benefits of binary compatibility offered qt across major version. code may still compile cease work when switch minor version of qt!

the below applies qt 5.2.0, have not looked @ other versions!

so, suppose want intercept call qlabel::setnum. you'd catch such events follows:

#include <private/qobject_p.h> // declaration of qmetacallevent  bool object::eventfilter(qobject * watched, qevent * event) {   qlabel * label = qobject_cast<qlabel*>(watched);   if (! label || event->type() != qevent::metacall) return false;   qmetacallevent * mev = static_cast<qmetacallevent*>(event);   static int setnumidx = qlabel::staticmetaobject.indexofslot("setnum(int)");   if (mev->id() != setnumidx) return false;   int num = *reinterpret_cast<int*>(mev->args()[1]);   // @ point, can invoke setnum ourselves , discard event   label->setnum(num);   return true; } 

if want see, globally, slots called using metacall system, can too. template parametrization of base class allows flexibility use application class - qcoreapplication, qguiapplication, qapplication, or user-derived type.

template <class base> class metacallwatcher : public base {   metacallwatcher(int& argc, char** argv) : base(argc, argv) {}   bool notify(qobject * receiver, qevent * event) {      if (event->type() == qevent::metacall) {       qmetacallevent * mev = static_cast<qmetacallevent*>(event);       qmetamethod slot = receiver->metaobject()->method(mev->id());       qdebug() << "metacall:" << receiver << slot.methodsignature();     }     return base::notify(receiver, event);   } }  int main(int argc, char ** argv) {   metacallwatcher<qapplication> app(argc, argv);   ... } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -