Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstracteventdispatcher.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:header-decls-only
4
5#ifndef QABSTRACTEVENTDISPATCHER_H
6#define QABSTRACTEVENTDISPATCHER_H
7
8#include <QtCore/qobject.h>
9#include <QtCore/qeventloop.h>
10
11QT_BEGIN_NAMESPACE
12
13class QAbstractNativeEventFilter;
14class QAbstractEventDispatcherPrivate;
15class QSocketNotifier;
16
17class Q_CORE_EXPORT QAbstractEventDispatcher : public QObject
18{
19 Q_OBJECT
20 Q_DECLARE_PRIVATE(QAbstractEventDispatcher)
21
22public:
23 using Duration = std::chrono::nanoseconds;
24 struct TimerInfo
25 {
26 int timerId;
27 int interval;
28 Qt::TimerType timerType;
29#ifndef Q_QDOC
30#ifndef __cpp_aggregate_paren_init
31 TimerInfo() = default;
32 inline TimerInfo(int id, int i, Qt::TimerType t)
33 : timerId(id), interval(i), timerType(t) { }
34#endif
35#endif
36 };
37 struct TimerInfoV2
38 {
39 Duration interval;
40 Qt::TimerId timerId;
41 Qt::TimerType timerType;
42 };
43
44 explicit QAbstractEventDispatcher(QObject *parent = nullptr);
45 ~QAbstractEventDispatcher();
46
47 static QAbstractEventDispatcher *instance(QThread *thread = nullptr);
48
49 virtual bool processEvents(QEventLoop::ProcessEventsFlags flags) = 0;
50
51 virtual void registerSocketNotifier(QSocketNotifier *notifier) = 0;
52 virtual void unregisterSocketNotifier(QSocketNotifier *notifier) = 0;
53
54 Qt::TimerId registerTimer(Duration interval, Qt::TimerType timerType, QObject *object);
55
56#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
57 int registerTimer(qint64 interval, Qt::TimerType timerType, QObject *object);
58
59 // old, integer-based API
60 virtual void registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object) = 0;
61 virtual bool unregisterTimer(int timerId) = 0;
62 virtual bool unregisterTimers(QObject *object) = 0;
63 virtual QList<TimerInfo> registeredTimers(QObject *object) const = 0;
64 virtual int remainingTime(int timerId) = 0;
65
66 void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object);
67 bool unregisterTimer(Qt::TimerId timerId);
68 QList<TimerInfoV2> timersForObject(QObject *object) const;
69 Duration remainingTime(Qt::TimerId timerId) const;
70#else
71 virtual void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object) = 0;
72 virtual bool unregisterTimer(Qt::TimerId timerId) = 0;
73 virtual bool unregisterTimers(QObject *object) = 0;
74 virtual QList<TimerInfoV2> timersForObject(QObject *object) const = 0;
75 virtual Duration remainingTime(Qt::TimerId timerId) const = 0;
76#endif
77
78 virtual void wakeUp() = 0;
79 virtual void interrupt() = 0;
80
81 virtual void startingUp();
82 virtual void closingDown();
83
84 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
85 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
86 bool filterNativeEvent(const QByteArray &eventType, void *message, qintptr *result);
87
88Q_SIGNALS:
89 void aboutToBlock();
90 void awake();
91
92protected:
93 QAbstractEventDispatcher(QAbstractEventDispatcherPrivate &,
94 QObject *parent);
95};
96
97Q_DECLARE_TYPEINFO(QAbstractEventDispatcher::TimerInfo, Q_PRIMITIVE_TYPE);
98Q_DECLARE_TYPEINFO(QAbstractEventDispatcher::TimerInfoV2, Q_PRIMITIVE_TYPE);
99
100#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
101class Q_CORE_EXPORT QAbstractEventDispatcherV2 : public QAbstractEventDispatcher
102{
103 Q_OBJECT
104 Q_DECLARE_PRIVATE(QAbstractEventDispatcher) // not V2
105
106public:
107 explicit QAbstractEventDispatcherV2(QObject *parent = nullptr);
108 ~QAbstractEventDispatcherV2() override;
109
110 // new virtuals
111 virtual void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType,
112 QObject *object) = 0;
113 virtual bool unregisterTimer(Qt::TimerId timerId) = 0;
114 virtual QList<TimerInfoV2> timersForObject(QObject *object) const = 0;
115 virtual Duration remainingTime(Qt::TimerId timerId) const = 0;
116 virtual bool processEventsWithDeadline(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline); // reserved for 6.9
117
118protected:
119 QAbstractEventDispatcherV2(QAbstractEventDispatcherPrivate &, QObject *parent);
120
121private:
122QT_WARNING_PUSH
123QT_WARNING_DISABLE_GCC("-Woverloaded-virtual")
124QT_WARNING_DISABLE_CLANG("-Woverloaded-virtual")
125 // final overrides from V1
126 void registerTimer(int timerId, qint64 interval, Qt::TimerType timerType,
127 QObject *object) final;
128 bool unregisterTimer(int timerId) final;
129 QList<TimerInfo> registeredTimers(QObject *object) const final;
130 int remainingTime(int timerId) final;
131QT_WARNING_POP
132};
133#else
134using QAbstractEventDispatcherV2 = QAbstractEventDispatcher;
135#endif // Qt 7
136
137QT_END_NAMESPACE
138
139#endif // QABSTRACTEVENTDISPATCHER_H
Combined button and popup list for selecting options.
QFreeList< void, QtTimerIdFreeListConstants > QtTimerIdFreeList
static const int Sizes[BlockCount]