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
qeventloop.h
Go to the documentation of this file.
1// Copyright (C) 2016 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
4#ifndef QEVENTLOOP_H
5#define QEVENTLOOP_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qdeadlinetimer.h>
9
11
13class QEventLoopPrivate;
14
15class Q_CORE_EXPORT QEventLoop : public QObject
16{
17 Q_OBJECT
18 Q_DECLARE_PRIVATE(QEventLoop)
19 friend class QEventLoopLocker;
20
21public:
22 explicit QEventLoop(QObject *parent = nullptr);
23 ~QEventLoop();
24
25 enum ProcessEventsFlag {
26 AllEvents = 0x00,
27 ExcludeUserInputEvents = 0x01,
28 ExcludeSocketNotifiers = 0x02,
29 WaitForMoreEvents = 0x04,
30 X11ExcludeTimers = 0x08,
31 EventLoopExec = 0x20,
32 DialogExec = 0x40,
33 ApplicationExec = 0x80,
34 };
35 Q_DECLARE_FLAGS(ProcessEventsFlags, ProcessEventsFlag)
36 Q_FLAG(ProcessEventsFlags)
37
38 bool processEvents(ProcessEventsFlags flags = AllEvents);
39 void processEvents(ProcessEventsFlags flags, int maximumTime);
40 void processEvents(ProcessEventsFlags flags, QDeadlineTimer deadline);
41
42 int exec(ProcessEventsFlags flags = AllEvents);
43 bool isRunning() const;
44
45 void wakeUp();
46
47 bool event(QEvent *event) override;
48
49public Q_SLOTS:
50 void exit(int returnCode = 0);
51 void quit();
52};
53
54Q_DECLARE_OPERATORS_FOR_FLAGS(QEventLoop::ProcessEventsFlags)
55
56class QEventLoopLockerPrivate;
57
59{
60public:
61 Q_NODISCARD_CTOR Q_CORE_EXPORT QEventLoopLocker() noexcept;
65
69
70 void swap(QEventLoopLocker &other) noexcept { std::swap(p, other.p); }
71 friend void swap(QEventLoopLocker &lhs, QEventLoopLocker &rhs) noexcept { lhs.swap(rhs); }
72
73private:
76
77 //
78 // Private implementation details.
79 // Do not call from public inline API!
80 //
81 enum class Type : quintptr {
82 EventLoop,
83 Thread,
84 Application,
85 };
86 explicit QEventLoopLocker(void *ptr, Type t) noexcept;
87 quintptr p;
88 static constexpr quintptr TypeMask = 0x3;
89 Type type() const { return Type(p & TypeMask); }
90 void *pointer() const { return reinterpret_cast<void *>(p & ~TypeMask); }
91 template <typename Func>
92 void visit(Func func) const;
93};
94
95QT_END_NAMESPACE
96
97#endif // QEVENTLOOP_H
\inmodule QtCore
Definition qcoreevent.h:390
\inmodule QtCore
int scopeLevel() const
int loopLevel() const
QDeferredDeleteEvent(int loopLevel, int scopeLevel)
Constructs a deferred delete event with the given loop and scope level.
\inmodule QtCore
Definition qeventloop.h:59
Q_CORE_EXPORT ~QEventLoopLocker()
Destroys this event loop locker object.
\inmodule QtCore
Definition qeventloop.h:16
\inmodule QtCore
Definition qcoreevent.h:49
\inmodule QtCore
Definition qcoreevent.h:372
#define __has_include(x)
QString qAppName()
Q_TRACE_POINT(qtcore, QCoreApplication_notify_exit, bool consumed, bool filtered)
void QT_MANGLE_NAMESPACE qt_startup_hook()
static QString qAppFileName()
QList< QtStartUpFunction > QStartUpFuncList
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
QString qtTrId(const char *id, int n)
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_exit)
static void qt_call_pre_routines()
qsizetype qGlobalPostedEventsCount()
static Q_CONSTINIT bool preRoutinesCalled
QList< QtCleanUpFunction > QVFuncList
static void replacePercentN(QString *result, int n)
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_event_compressed, QObject *receiver, QEvent *event)
QString qTrId(const char *id, int n)
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_entry, QObject *receiver, QEvent *event, QEvent::Type type)
Q_TRACE_PREFIX(qtcore, "#include <qcoreevent.h>")
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction)
void(* QtCleanUpFunction)()
void(* QtStartUpFunction)()
Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction)
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction)
#define qApp
#define Q_EVENT_DISABLE_COPY(Class)
Definition qcoreevent.h:16
#define Q_DECL_EVENT_COMMON(Class)
Definition qcoreevent.h:23
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)