Qt 4.8
Public Functions | Private Functions | Friends | List of all members
QEventDispatcherWin32 Class Reference

#include <qeventdispatcher_win_p.h>

Inheritance diagram for QEventDispatcherWin32:
QAbstractEventDispatcher QObject QGuiEventDispatcherWin32

Public Functions

void activateEventNotifiers ()
 
void closingDown ()
 
bool event (QEvent *e)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
void flush ()
 Flushes the event queue. More...
 
bool hasPendingEvents ()
 Returns true if there is an event waiting; otherwise returns false. More...
 
void interrupt ()
 Interrupts event dispatching; i. More...
 
bool QT_ENSURE_STACK_ALIGNED_FOR_SSE processEvents (QEventLoop::ProcessEventsFlags flags)
 Processes pending events that match flags until there are no more events to process. More...
 
 QEventDispatcherWin32 (QObject *parent=0)
 
QList< TimerInforegisteredTimers (QObject *object) const
 Returns a list of registered timers for object. More...
 
bool registerEventNotifier (QWinEventNotifier *notifier)
 
void registerSocketNotifier (QSocketNotifier *notifier)
 Registers notifier with the event loop. More...
 
void registerTimer (int timerId, int interval, QObject *object)
 Register a timer with the specified timerId and interval for the given object. More...
 
void startingUp ()
 
void unregisterEventNotifier (QWinEventNotifier *notifier)
 
void unregisterSocketNotifier (QSocketNotifier *notifier)
 Unregisters notifier from the event dispatcher. More...
 
bool unregisterTimer (int timerId)
 Unregisters the timer with the given timerId. More...
 
bool unregisterTimers (QObject *object)
 Unregisters all the timers associated with the given object. More...
 
void wakeUp ()
 Wakes up the event loop. More...
 
 ~QEventDispatcherWin32 ()
 
- Public Functions inherited from QAbstractEventDispatcher
bool filterEvent (void *message)
 Sends message through the event filter that was set by setEventFilter(). More...
 
 QAbstractEventDispatcher (QObject *parent=0)
 Constructs a new event dispatcher with the given parent. More...
 
int registerTimer (int interval, QObject *object)
 Registers a timer with the specified interval for the given object. More...
 
EventFilter setEventFilter (EventFilter filter)
 Replaces the event filter function for this QAbstractEventDispatcher with filter and returns the replaced event filter function. More...
 
 ~QAbstractEventDispatcher ()
 Destroys the event dispatcher. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Functions

void createInternalHwnd ()
 

Friends

class QGuiEventDispatcherWin32
 
LRESULT QT_WIN_CALLBACK qt_GetMessageHook (int, WPARAM, LPARAM)
 
LRESULT QT_WIN_CALLBACK qt_internal_proc (HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
 

Additional Inherited Members

- Public Types inherited from QAbstractEventDispatcher
typedef bool(* EventFilter) (void *message)
 Typedef for a function with the signature. More...
 
typedef QPair< int, int > TimerInfo
 Typedef for QPair<int, int>. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractEventDispatcher
void aboutToBlock ()
 This signal is emitted before the event loop calls a function that could block. More...
 
void awake ()
 This signal is emitted after the event loop returns from a function that could block. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QAbstractEventDispatcher
static QAbstractEventDispatcherinstance (QThread *thread=0)
 Returns a pointer to the event dispatcher object for the specified thread. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QAbstractEventDispatcher
 QAbstractEventDispatcher (QAbstractEventDispatcherPrivate &, QObject *parent)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 67 of file qeventdispatcher_win_p.h.

Constructors and Destructors

◆ QEventDispatcherWin32()

QEventDispatcherWin32::QEventDispatcherWin32 ( QObject parent = 0)
explicit

Definition at line 712 of file qeventdispatcher_win.cpp.

Referenced by QGuiEventDispatcherWin32::processEvents().

714 {
715 }
QAbstractEventDispatcher(QObject *parent=0)
Constructs a new event dispatcher with the given parent.

◆ ~QEventDispatcherWin32()

QEventDispatcherWin32::~QEventDispatcherWin32 ( )

Definition at line 717 of file qeventdispatcher_win.cpp.

718 {
719 }

Functions

◆ activateEventNotifiers()

void QEventDispatcherWin32::activateEventNotifiers ( )

Definition at line 1076 of file qeventdispatcher_win.cpp.

1077 {
1079  //### this could break if events are removed/added in the activation
1080  for (int i=0; i<d->winEventNotifierList.count(); i++) {
1081 #if !defined(Q_OS_WINCE)
1082  if (WaitForSingleObjectEx(d->winEventNotifierList.at(i)->handle(), 0, TRUE) == WAIT_OBJECT_0)
1083  d->activateEventNotifier(d->winEventNotifierList.at(i));
1084 #else
1085  if (WaitForSingleObject(d->winEventNotifierList.at(i)->handle(), 0) == WAIT_OBJECT_0)
1086  d->activateEventNotifier(d->winEventNotifierList.at(i));
1087 #endif
1088  }
1089 }
double d
Definition: qnumeric_p.h:62
#define WAIT_OBJECT_0
#define Q_D(Class)
Definition: qglobal.h:2482
#define TRUE
Synonym for true.
Definition: qglobal.h:1018

◆ closingDown()

void QEventDispatcherWin32::closingDown ( )
virtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractEventDispatcher.

Definition at line 1114 of file qeventdispatcher_win.cpp.

1115 {
1117 
1118  // clean up any socketnotifiers
1119  while (!d->sn_read.isEmpty())
1120  unregisterSocketNotifier((*(d->sn_read.begin()))->obj);
1121  while (!d->sn_write.isEmpty())
1122  unregisterSocketNotifier((*(d->sn_write.begin()))->obj);
1123  while (!d->sn_except.isEmpty())
1124  unregisterSocketNotifier((*(d->sn_except.begin()))->obj);
1125 
1126  // clean up any timers
1127  for (int i = 0; i < d->timerVec.count(); ++i)
1128  d->unregisterTimer(d->timerVec.at(i), true);
1129  d->timerVec.clear();
1130  d->timerDict.clear();
1131 
1132 #ifndef Q_OS_WINCE
1133  if (d->getMessageHook)
1134  UnhookWindowsHookEx(d->getMessageHook);
1135  d->getMessageHook = 0;
1136 #endif
1137 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void unregisterSocketNotifier(QSocketNotifier *notifier)
Unregisters notifier from the event dispatcher.

◆ createInternalHwnd()

void QEventDispatcherWin32::createInternalHwnd ( )
private

Definition at line 680 of file qeventdispatcher_win.cpp.

Referenced by processEvents(), and QGuiEventDispatcherWin32::QGuiEventDispatcherWin32().

681 {
683 
684  Q_ASSERT(!d->internalHwnd);
685  if (d->internalHwnd)
686  return;
687  d->internalHwnd = qt_create_internal_window(this);
688 
689 #ifndef Q_OS_WINCE
690  // setup GetMessage hook needed to drive our posted events
691  d->getMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) qt_GetMessageHook, NULL, GetCurrentThreadId());
692  if (!d->getMessageHook) {
693  qFatal("Qt: INTERNALL ERROR: failed to install GetMessage hook");
694  }
695 #endif
696 
697  // register all socket notifiers
698  QList<int> sockets = (d->sn_read.keys().toSet()
699  + d->sn_write.keys().toSet()
700  + d->sn_except.keys().toSet()).toList();
701  for (int i = 0; i < sockets.count(); ++i)
702  d->doWsaAsyncSelect(sockets.at(i));
703 
704  // start all normal timers
705  for (int i = 0; i < d->timerVec.count(); ++i)
706  d->registerTimer(d->timerVec.at(i));
707 
708  // trigger a call to sendPostedEvents()
709  wakeUp();
710 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QList< QVariant > toList(char **buf, int count, T *=0)
Definition: qsql_ibase.cpp:472
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void wakeUp()
Wakes up the event loop.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qFatal(const char *,...)
static HWND qt_create_internal_window(const QEventDispatcherWin32 *eventDispatcher)
friend LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int, WPARAM, LPARAM)

◆ event()

bool QEventDispatcherWin32::event ( QEvent e)
virtual

This virtual function receives events to an object and should return true if the event e was recognized and processed.

The event() function can be reimplemented to customize the behavior of an object.

See also
installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), QWidget::event()

Reimplemented from QObject.

Definition at line 1139 of file qeventdispatcher_win.cpp.

Referenced by QETWidget::translateGestureEvent().

1140 {
1142  if (e->type() == QEvent::ZeroTimerEvent) {
1143  QZeroTimerEvent *zte = static_cast<QZeroTimerEvent*>(e);
1144  WinTimerInfo *t = d->timerDict.value(zte->timerId());
1145  if (t) {
1146  t->inTimerEvent = true;
1147 
1148  QTimerEvent te(zte->timerId());
1150 
1151  t = d->timerDict.value(zte->timerId());
1152  if (t) {
1153  if (t->interval == 0 && t->inTimerEvent) {
1154  // post the next zero timer event as long as the timer was not restarted
1156  }
1157 
1158  t->inTimerEvent = false;
1159  }
1160  }
1161  return true;
1162  } else if (e->type() == QEvent::Timer) {
1163  QTimerEvent *te = static_cast<QTimerEvent*>(e);
1164  d->sendTimerEvent(te->timerId());
1165  }
1167 }
double d
Definition: qnumeric_p.h:62
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ flush()

void QEventDispatcherWin32::flush ( )
virtual

Flushes the event queue.

This normally returns almost immediately. Does nothing on platforms other than X11.

Implements QAbstractEventDispatcher.

Definition at line 1108 of file qeventdispatcher_win.cpp.

1109 { }

◆ hasPendingEvents()

bool QEventDispatcherWin32::hasPendingEvents ( )
virtual

Returns true if there is an event waiting; otherwise returns false.

Implements QAbstractEventDispatcher.

Definition at line 864 of file qeventdispatcher_win.cpp.

865 {
866  MSG msg;
867  return qGlobalPostedEventsCount() || PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
868 }
struct tagMSG MSG
uint qGlobalPostedEventsCount()

◆ interrupt()

void QEventDispatcherWin32::interrupt ( )
virtual

Interrupts event dispatching; i.

e. the event dispatcher will return from processEvents() as soon as possible.

Implements QAbstractEventDispatcher.

Definition at line 1101 of file qeventdispatcher_win.cpp.

1102 {
1104  d->interrupt = true;
1105  wakeUp();
1106 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void wakeUp()
Wakes up the event loop.

◆ processEvents()

bool QEventDispatcherWin32::processEvents ( QEventLoop::ProcessEventsFlags  flags)
virtual

Processes pending events that match flags until there are no more events to process.

Returns true if an event was processed; otherwise returns false.

This function is especially useful if you have a long running operation and want to show its progress without allowing user input; i.e. by using the QEventLoop::ExcludeUserInputEvents flag.

If the QEventLoop::WaitForMoreEvents flag is set in flags, the behavior of this function is as follows:

  • If events are available, this function returns after processing them.

  • If no events are available, this function will wait until more are available and return after processing newly available events.

If the QEventLoop::WaitForMoreEvents flag is not set in flags, and no events are available, this function will return immediately.

Note: This function does not process events continuously; it returns after all available events are processed.

See also
hasPendingEvents()

Implements QAbstractEventDispatcher.

Reimplemented in QGuiEventDispatcherWin32.

Definition at line 721 of file qeventdispatcher_win.cpp.

Referenced by QGuiEventDispatcherWin32::processEvents().

722 {
724 
725  if (!d->internalHwnd)
727 
728  d->interrupt = false;
729  emit awake();
730 
731  bool canWait;
732  bool retVal = false;
733  bool seenWM_QT_SENDPOSTEDEVENTS = false;
734  bool needWM_QT_SENDPOSTEDEVENTS = false;
735  do {
736  DWORD waitRet = 0;
737  HANDLE pHandles[MAXIMUM_WAIT_OBJECTS - 1];
738  QVarLengthArray<MSG> processedTimers;
739  while (!d->interrupt) {
740  DWORD nCount = d->winEventNotifierList.count();
741  Q_ASSERT(nCount < MAXIMUM_WAIT_OBJECTS - 1);
742 
743  MSG msg;
744  bool haveMessage;
745 
746  if (!(flags & QEventLoop::ExcludeUserInputEvents) && !d->queuedUserInputEvents.isEmpty()) {
747  // process queued user input events
748  haveMessage = true;
749  msg = d->queuedUserInputEvents.takeFirst();
750  } else if(!(flags & QEventLoop::ExcludeSocketNotifiers) && !d->queuedSocketEvents.isEmpty()) {
751  // process queued socket events
752  haveMessage = true;
753  msg = d->queuedSocketEvents.takeFirst();
754  } else {
755  haveMessage = PeekMessage(&msg, 0, 0, 0, PM_REMOVE);
756  if (haveMessage && (flags & QEventLoop::ExcludeUserInputEvents)
757  && ((msg.message >= WM_KEYFIRST
758  && msg.message <= WM_KEYLAST)
759  || (msg.message >= WM_MOUSEFIRST
760  && msg.message <= WM_MOUSELAST)
761  || msg.message == WM_MOUSEWHEEL
762  || msg.message == WM_MOUSEHWHEEL
763  || msg.message == WM_TOUCH
764 #ifndef QT_NO_GESTURES
765  || msg.message == WM_GESTURE
766  || msg.message == WM_GESTURENOTIFY
767 #endif
768  || msg.message == WM_CLOSE)) {
769  // queue user input events for later processing
770  haveMessage = false;
771  d->queuedUserInputEvents.append(msg);
772  }
773  if (haveMessage && (flags & QEventLoop::ExcludeSocketNotifiers)
774  && (msg.message == WM_QT_SOCKETNOTIFIER && msg.hwnd == d->internalHwnd)) {
775  // queue socket events for later processing
776  haveMessage = false;
777  d->queuedSocketEvents.append(msg);
778  }
779  }
780  if (!haveMessage) {
781  // no message - check for signalled objects
782  for (int i=0; i<(int)nCount; i++)
783  pHandles[i] = d->winEventNotifierList.at(i)->handle();
784  waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, 0, QS_ALLINPUT, MWMO_ALERTABLE);
785  if ((haveMessage = (waitRet == WAIT_OBJECT_0 + nCount))) {
786  // a new message has arrived, process it
787  continue;
788  }
789  }
790  if (haveMessage) {
791 #ifdef Q_OS_WINCE
792  // WinCE doesn't support hooks at all, so we have to call this by hand :(
793  (void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM) &msg);
794 #endif
795 
796  if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) {
797  if (seenWM_QT_SENDPOSTEDEVENTS) {
798  // when calling processEvents() "manually", we only want to send posted
799  // events once
800  needWM_QT_SENDPOSTEDEVENTS = true;
801  continue;
802  }
803  seenWM_QT_SENDPOSTEDEVENTS = true;
804  } else if (msg.message == WM_TIMER) {
805  // avoid live-lock by keeping track of the timers we've already sent
806  bool found = false;
807  for (int i = 0; !found && i < processedTimers.count(); ++i) {
808  const MSG processed = processedTimers.constData()[i];
809  found = (processed.wParam == msg.wParam && processed.hwnd == msg.hwnd && processed.lParam == msg.lParam);
810  }
811  if (found)
812  continue;
813  processedTimers.append(msg);
814  } else if (msg.message == WM_QUIT) {
817  return false;
818  }
819 
820  if (!filterEvent(&msg)) {
821  TranslateMessage(&msg);
822  DispatchMessage(&msg);
823  }
824  } else if (waitRet < WAIT_OBJECT_0 + nCount) {
825  d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0));
826  } else {
827  // nothing todo so break
828  break;
829  }
830  retVal = true;
831  }
832 
833  // still nothing - wait for message or signalled objects
834  canWait = (!retVal
835  && !d->interrupt
836  && (flags & QEventLoop::WaitForMoreEvents));
837  if (canWait) {
838  DWORD nCount = d->winEventNotifierList.count();
839  Q_ASSERT(nCount < MAXIMUM_WAIT_OBJECTS - 1);
840  for (int i=0; i<(int)nCount; i++)
841  pHandles[i] = d->winEventNotifierList.at(i)->handle();
842 
843  emit aboutToBlock();
844  waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE | MWMO_INPUTAVAILABLE);
845  emit awake();
846  if (waitRet < WAIT_OBJECT_0 + nCount) {
847  d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0));
848  retVal = true;
849  }
850  }
851  } while (canWait);
852 
853  if (!seenWM_QT_SENDPOSTEDEVENTS && (flags & QEventLoop::EventLoopExec) == 0) {
854  // when called "manually", always send posted events
855  QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
856  }
857 
858  if (needWM_QT_SENDPOSTEDEVENTS)
859  PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0);
860 
861  return retVal;
862 }
#define WM_MOUSEWHEEL
Definition: qt_windows.h:116
double d
Definition: qnumeric_p.h:62
#define QT_NO_GESTURES
const T * constData() const
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data)
bool filterEvent(void *message)
Sends message through the event filter that was set by setEventFilter().
#define WM_MOUSEHWHEEL
Definition: qt_windows.h:119
#define WM_GESTURENOTIFY
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define WAIT_OBJECT_0
#define Q_D(Class)
Definition: qglobal.h:2482
void append(const T &t)
static void quit()
Tells the application to exit with return code 0 (success).
void awake()
This signal is emitted after the event loop returns from a function that could block.
#define emit
Definition: qobjectdefs.h:76
#define WM_GESTURE
void * HANDLE
Definition: qnamespace.h:1671
int count() const
struct tagMSG MSG
void aboutToBlock()
This signal is emitted before the event loop calls a function that could block.
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
friend LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int, WPARAM, LPARAM)
#define MWMO_ALERTABLE
#define WM_TOUCH

◆ registeredTimers()

QList< QEventDispatcherWin32::TimerInfo > QEventDispatcherWin32::registeredTimers ( QObject object) const
virtual

Returns a list of registered timers for object.

The timer ID is the first member in each pair; the interval is the second.

Implements QAbstractEventDispatcher.

Definition at line 1019 of file qeventdispatcher_win.cpp.

1020 {
1021  if (!object) {
1022  qWarning("QEventDispatcherWin32:registeredTimers: invalid argument");
1023  return QList<TimerInfo>();
1024  }
1025 
1026  Q_D(const QEventDispatcherWin32);
1027  QList<TimerInfo> list;
1028  for (int i = 0; i < d->timerVec.size(); ++i) {
1029  const WinTimerInfo *t = d->timerVec.at(i);
1030  if (t && t->obj == object)
1031  list << TimerInfo(t->timerId, t->interval);
1032  }
1033  return list;
1034 }
double d
Definition: qnumeric_p.h:62
QPair< int, int > TimerInfo
Typedef for QPair<int, int>.
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ registerEventNotifier()

bool QEventDispatcherWin32::registerEventNotifier ( QWinEventNotifier notifier)

Definition at line 1036 of file qeventdispatcher_win.cpp.

Referenced by QWinEventNotifier::QWinEventNotifier(), and QWinEventNotifier::setEnabled().

1037 {
1038  if (!notifier) {
1039  qWarning("QWinEventNotifier: Internal error");
1040  return false;
1041  } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
1042  qWarning("QWinEventNotifier: event notifiers cannot be enabled from another thread");
1043  return false;
1044  }
1045 
1047 
1048  if (d->winEventNotifierList.contains(notifier))
1049  return true;
1050 
1051  if (d->winEventNotifierList.count() >= MAXIMUM_WAIT_OBJECTS - 2) {
1052  qWarning("QWinEventNotifier: Cannot have more than %d enabled at one time", MAXIMUM_WAIT_OBJECTS - 2);
1053  return false;
1054  }
1055  d->winEventNotifierList.append(notifier);
1056  return true;
1057 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ registerSocketNotifier()

void QEventDispatcherWin32::registerSocketNotifier ( QSocketNotifier notifier)
virtual

Registers notifier with the event loop.

Subclasses must implement this method to tie a socket notifier into another event loop.

Implements QAbstractEventDispatcher.

Definition at line 870 of file qeventdispatcher_win.cpp.

871 {
872  Q_ASSERT(notifier);
873  int sockfd = notifier->socket();
874  int type = notifier->type();
875 #ifndef QT_NO_DEBUG
876  if (sockfd < 0) {
877  qWarning("QSocketNotifier: Internal error");
878  return;
879  } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
880  qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread");
881  return;
882  }
883 #endif
884 
886  QSNDict *sn_vec[3] = { &d->sn_read, &d->sn_write, &d->sn_except };
887  QSNDict *dict = sn_vec[type];
888 
889  if (QCoreApplication::closingDown()) // ### d->exitloop?
890  return; // after sn_cleanup, don't reinitialize.
891 
892  if (dict->contains(sockfd)) {
893  const char *t[] = { "Read", "Write", "Exception" };
894  /* Variable "socket" below is a function pointer. */
895  qWarning("QSocketNotifier: Multiple socket notifiers for "
896  "same socket %d and type %s", sockfd, t[type]);
897  }
898 
899  QSockNot *sn = new QSockNot;
900  sn->obj = notifier;
901  sn->fd = sockfd;
902  dict->insert(sn->fd, sn);
903 
904  if (d->internalHwnd)
905  d->doWsaAsyncSelect(sockfd);
906 }
double d
Definition: qnumeric_p.h:62
QSocketNotifier * obj
int type
Definition: qmetatype.cpp:239
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
Type type() const
Returns the socket event type specified to the constructor.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
int socket() const
Returns the socket identifier specified to the constructor.

◆ registerTimer()

void QEventDispatcherWin32::registerTimer ( int  timerId,
int  interval,
QObject object 
)
virtual

Register a timer with the specified timerId and interval for the given object.

Implements QAbstractEventDispatcher.

Definition at line 937 of file qeventdispatcher_win.cpp.

938 {
939  if (timerId < 1 || interval < 0 || !object) {
940  qWarning("QEventDispatcherWin32::registerTimer: invalid arguments");
941  return;
942  } else if (object->thread() != thread() || thread() != QThread::currentThread()) {
943  qWarning("QObject::startTimer: timers cannot be started from another thread");
944  return;
945  }
946 
948 
949  register WinTimerInfo *t = new WinTimerInfo;
950  t->dispatcher = this;
951  t->timerId = timerId;
952  t->interval = interval;
953  t->obj = object;
954  t->inTimerEvent = false;
955  t->fastTimerId = 0;
956 
957  if (d->internalHwnd)
958  d->registerTimer(t);
959 
960  d->timerVec.append(t); // store in timer vector
961  d->timerDict.insert(t->timerId, t); // store timers in dict
962 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ startingUp()

void QEventDispatcherWin32::startingUp ( )
virtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractEventDispatcher.

Definition at line 1111 of file qeventdispatcher_win.cpp.

1112 { }

◆ unregisterEventNotifier()

void QEventDispatcherWin32::unregisterEventNotifier ( QWinEventNotifier notifier)

Definition at line 1059 of file qeventdispatcher_win.cpp.

Referenced by QWinEventNotifier::setEnabled().

1060 {
1061  if (!notifier) {
1062  qWarning("QWinEventNotifier: Internal error");
1063  return;
1064  } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
1065  qWarning("QWinEventNotifier: event notifiers cannot be disabled from another thread");
1066  return;
1067  }
1068 
1070 
1071  int i = d->winEventNotifierList.indexOf(notifier);
1072  if (i != -1)
1073  d->winEventNotifierList.takeAt(i);
1074 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ unregisterSocketNotifier()

void QEventDispatcherWin32::unregisterSocketNotifier ( QSocketNotifier notifier)
virtual

Unregisters notifier from the event dispatcher.

Subclasses must reimplement this method to tie a socket notifier into another event loop. Reimplementations must call the base implementation.

Implements QAbstractEventDispatcher.

Definition at line 908 of file qeventdispatcher_win.cpp.

Referenced by closingDown().

909 {
910  Q_ASSERT(notifier);
911  int sockfd = notifier->socket();
912  int type = notifier->type();
913 #ifndef QT_NO_DEBUG
914  if (sockfd < 0) {
915  qWarning("QSocketNotifier: Internal error");
916  return;
917  } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
918  qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread");
919  return;
920  }
921 #endif
922 
924  QSNDict *sn_vec[3] = { &d->sn_read, &d->sn_write, &d->sn_except };
925  QSNDict *dict = sn_vec[type];
926  QSockNot *sn = dict->value(sockfd);
927  if (!sn)
928  return;
929 
930  dict->remove(sockfd);
931  delete sn;
932 
933  if (d->internalHwnd)
934  d->doWsaAsyncSelect(sockfd);
935 }
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
Type type() const
Returns the socket event type specified to the constructor.
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
int socket() const
Returns the socket identifier specified to the constructor.

◆ unregisterTimer()

bool QEventDispatcherWin32::unregisterTimer ( int  timerId)
virtual

Unregisters the timer with the given timerId.

Returns true if successful; otherwise returns false.

See also
registerTimer(), unregisterTimers()

Implements QAbstractEventDispatcher.

Definition at line 964 of file qeventdispatcher_win.cpp.

965 {
966  if (timerId < 1) {
967  qWarning("QEventDispatcherWin32::unregisterTimer: invalid argument");
968  return false;
969  }
970  QThread *currentThread = QThread::currentThread();
971  if (thread() != currentThread) {
972  qWarning("QObject::killTimer: timers cannot be stopped from another thread");
973  return false;
974  }
975 
977  if (d->timerVec.isEmpty() || timerId <= 0)
978  return false;
979 
980  WinTimerInfo *t = d->timerDict.value(timerId);
981  if (!t)
982  return false;
983 
984  d->timerDict.remove(t->timerId);
985  d->timerVec.removeAll(t);
986  d->unregisterTimer(t);
987  return true;
988 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59

◆ unregisterTimers()

bool QEventDispatcherWin32::unregisterTimers ( QObject object)
virtual

Unregisters all the timers associated with the given object.

Returns true if all timers were successful removed; otherwise returns false.

See also
unregisterTimer(), registeredTimers()

Implements QAbstractEventDispatcher.

Definition at line 990 of file qeventdispatcher_win.cpp.

991 {
992  if (!object) {
993  qWarning("QEventDispatcherWin32::unregisterTimers: invalid argument");
994  return false;
995  }
996  QThread *currentThread = QThread::currentThread();
997  if (object->thread() != thread() || thread() != currentThread) {
998  qWarning("QObject::killTimers: timers cannot be stopped from another thread");
999  return false;
1000  }
1001 
1003  if (d->timerVec.isEmpty())
1004  return false;
1005  register WinTimerInfo *t;
1006  for (int i=0; i<d->timerVec.size(); i++) {
1007  t = d->timerVec.at(i);
1008  if (t && t->obj == object) { // object found
1009  d->timerDict.remove(t->timerId);
1010  d->timerVec.removeAt(i);
1011  d->unregisterTimer(t);
1012  --i;
1013  }
1014  }
1015  return true;
1016 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59

◆ wakeUp()

void QEventDispatcherWin32::wakeUp ( )
virtual

Wakes up the event loop.

Note
This class or function is threadsafe.
See also
awake()

Implements QAbstractEventDispatcher.

Definition at line 1091 of file qeventdispatcher_win.cpp.

Referenced by interrupt().

1092 {
1094  d->serialNumber.ref();
1095  if (d->internalHwnd && d->wakeUps.testAndSetAcquire(0, 1)) {
1096  // post a WM_QT_SENDPOSTEDEVENTS to this thread if there isn't one already pending
1097  PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0);
1098  }
1099 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

Friends and Related Functions

◆ QGuiEventDispatcherWin32

Definition at line 73 of file qeventdispatcher_win_p.h.

◆ qt_GetMessageHook

LRESULT QT_WIN_CALLBACK qt_GetMessageHook ( int  code,
WPARAM  wp,
LPARAM  lp 
)
friend

Definition at line 520 of file qeventdispatcher_win.cpp.

521 {
522  if (wp == PM_REMOVE) {
524  Q_ASSERT(q != 0);
525  if (q) {
526  MSG *msg = (MSG *) lp;
527  QEventDispatcherWin32Private *d = q->d_func();
528  int localSerialNumber = d->serialNumber;
529  static const UINT mask = inputTimerMask();
530  if (HIWORD(GetQueueStatus(mask)) == 0) {
531  // no more input or timer events in the message queue, we can allow posted events to be sent normally now
532  if (d->sendPostedEventsWindowsTimerId != 0) {
533  // stop the timer to send posted events, since we now allow the WM_QT_SENDPOSTEDEVENTS message
536  }
537  (void) d->wakeUps.fetchAndStoreRelease(0);
538  if (localSerialNumber != d->lastSerialNumber
539  // if this message IS the one that triggers sendPostedEvents(), no need to post it again
540  && (msg->hwnd != d->internalHwnd
541  || msg->message != WM_QT_SENDPOSTEDEVENTS)) {
542  PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0);
543  }
544  } else if (d->sendPostedEventsWindowsTimerId == 0
545  && localSerialNumber != d->lastSerialNumber) {
546  // start a special timer to continue delivering posted events while
547  // there are still input and timer messages in the message queue
550  0, // we specify zero, but Windows uses USER_TIMER_MINIMUM
551  NULL);
552  // we don't check the return value of SetTimer()... if creating the timer failed, there's little
553  // we can do. we just have to accept that posted events will be starved
554  }
555  }
556  }
557 #ifdef Q_OS_WINCE
558  Q_UNUSED(code);
559  return 0;
560 #else
561  return CallNextHookEx(0, code, wp, lp);
562 #endif
563 }
double d
Definition: qnumeric_p.h:62
static UINT inputTimerMask()
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
struct tagMSG MSG
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int fetchAndStoreRelease(int newValue)
Atomic fetch-and-store.

◆ qt_internal_proc

LRESULT QT_WIN_CALLBACK qt_internal_proc ( HWND  hwnd,
UINT  message,
WPARAM  wp,
LPARAM  lp 
)
friend

Definition at line 430 of file qeventdispatcher_win.cpp.

431 {
432  if (message == WM_NCCREATE)
433  return true;
434 
435  MSG msg;
436  msg.hwnd = hwnd;
437  msg.message = message;
438  msg.wParam = wp;
439  msg.lParam = lp;
441  long result;
442  if (!app) {
443  if (message == WM_TIMER)
444  KillTimer(hwnd, wp);
445  return 0;
446  } else if (app->filterEvent(&msg, &result)) {
447  return result;
448  }
449 
450 #ifdef GWLP_USERDATA
451  QEventDispatcherWin32 *q = (QEventDispatcherWin32 *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
452 #else
453  QEventDispatcherWin32 *q = (QEventDispatcherWin32 *) GetWindowLong(hwnd, GWL_USERDATA);
454 #endif
456  if (q != 0)
457  d = q->d_func();
458 
459  if (message == WM_QT_SOCKETNOTIFIER) {
460  // socket notifier message
461  int type = -1;
462  switch (WSAGETSELECTEVENT(lp)) {
463  case FD_READ:
464  case FD_CLOSE:
465  case FD_ACCEPT:
466  type = 0;
467  break;
468  case FD_WRITE:
469  case FD_CONNECT:
470  type = 1;
471  break;
472  case FD_OOB:
473  type = 2;
474  break;
475  }
476  if (type >= 0) {
477  Q_ASSERT(d != 0);
478  QSNDict *sn_vec[3] = { &d->sn_read, &d->sn_write, &d->sn_except };
479  QSNDict *dict = sn_vec[type];
480 
481  QSockNot *sn = dict ? dict->value(wp) : 0;
482  if (sn) {
485  }
486  }
487  return 0;
488  } else if (message == WM_QT_SENDPOSTEDEVENTS
489  // we also use a Windows timer to send posted events when the message queue is full
490  || (message == WM_TIMER
492  && wp == (uint)d->sendPostedEventsWindowsTimerId)) {
493  int localSerialNumber = d->serialNumber;
494  if (localSerialNumber != d->lastSerialNumber) {
495  d->lastSerialNumber = localSerialNumber;
497  }
498  return 0;
499  } else if (message == WM_TIMER) {
500  Q_ASSERT(d != 0);
501  d->sendTimerEvent(wp);
502  return 0;
503  }
504 
505  return DefWindowProc(hwnd, message, wp, lp);
506 }
double d
Definition: qnumeric_p.h:62
QSocketNotifier * obj
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data)
int type
Definition: qmetatype.cpp:239
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QThreadData * threadData
Definition: qobject_p.h:195
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool event(QEvent *e)
This virtual function receives events to an object and should return true if the event e was recogniz...
unsigned int uint
Definition: qglobal.h:996
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QCoreApplication class provides an event loop for console Qt applications.
struct tagMSG MSG
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
#define WSAGETSELECTEVENT(lParam)
bool filterEvent(void *message, long *result)
Sends message through the event filter that was set by setEventFilter().
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define WM_NCCREATE

The documentation for this class was generated from the following files: