Fix compilation with old g++ 3.3.5 and debian-sarge.
[wvstreams.git] / qt / wvqthook.cc
blob0a95865e2642e8021afba95de36aaa1d8e3051ff
1 /*
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().
9 */
10 #include "wvqthook.moc"
12 WvQtHook::WvQtHook(WvQtHookCallback _callback) :
13 callback(_callback)
18 void WvQtHook::setcallback(WvQtHookCallback _callback)
20 callback = _callback;
24 bool WvQtHook::event(QEvent *event)
26 if (! callback)
27 return false;
28 QEvent::Type eventtype = event->type();
29 if (eventtype < QEvent::User || eventtype > QEvent::MaxUser)
30 return false;
31 QCustomEvent *ce = static_cast<QCustomEvent*>(event);
32 callback(*this, eventtype - QEvent::User, ce->data());
33 return true;
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);