2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A Qt object that invokes its callback whenever it receives
6 * an event. This is useful for deferring processing to the
7 * Qt event loop. Use it to avoid problems resulting from the
8 * non-reentrant nature of WvStream::execute().
10 #include "wvqthook.moc"
12 WvQtHook::WvQtHook(WvQtHookCallback _callback
) :
18 void WvQtHook::setcallback(WvQtHookCallback _callback
)
24 bool WvQtHook::event(QEvent
*event
)
28 QEvent::Type eventtype
= event
->type();
29 if (eventtype
< QEvent::User
|| eventtype
> QEvent::MaxUser
)
31 QCustomEvent
*ce
= static_cast<QCustomEvent
*>(event
);
32 callback(*this, eventtype
- QEvent::User
, ce
->data());
37 void WvQtHook::post(int type
, void *data
)
39 // event must be allocated on heap for postEvent
40 QEvent::Type eventtype
= QEvent::Type(QEvent::User
+ type
);
41 QCustomEvent
*event
= new QCustomEvent(eventtype
, data
);
42 QApplication::postEvent(this, event
);
46 void WvQtHook::send(int type
, void *data
)
48 QEvent::Type eventtype
= QEvent::Type(QEvent::User
+ type
);
49 QCustomEvent
event(eventtype
, data
);
50 QApplication::sendEvent(this, & event
);