Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qeventloop.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QEVENTLOOP_H
0005 #define QEVENTLOOP_H
0006 
0007 #include <QtCore/qobject.h>
0008 #include <QtCore/qdeadlinetimer.h>
0009 
0010 QT_BEGIN_NAMESPACE
0011 
0012 class QEventLoopLocker;
0013 class QEventLoopPrivate;
0014 
0015 class Q_CORE_EXPORT QEventLoop : public QObject
0016 {
0017     Q_OBJECT
0018     Q_DECLARE_PRIVATE(QEventLoop)
0019     friend class QEventLoopLocker;
0020 
0021 public:
0022     explicit QEventLoop(QObject *parent = nullptr);
0023     ~QEventLoop();
0024 
0025     enum ProcessEventsFlag {
0026         AllEvents = 0x00,
0027         ExcludeUserInputEvents = 0x01,
0028         ExcludeSocketNotifiers = 0x02,
0029         WaitForMoreEvents = 0x04,
0030         X11ExcludeTimers = 0x08,
0031         EventLoopExec = 0x20,
0032         DialogExec = 0x40,
0033         ApplicationExec = 0x80,
0034     };
0035     Q_DECLARE_FLAGS(ProcessEventsFlags, ProcessEventsFlag)
0036     Q_FLAG(ProcessEventsFlags)
0037 
0038     bool processEvents(ProcessEventsFlags flags = AllEvents);
0039     void processEvents(ProcessEventsFlags flags, int maximumTime);
0040     void processEvents(ProcessEventsFlags flags, QDeadlineTimer deadline);
0041 
0042     int exec(ProcessEventsFlags flags = AllEvents);
0043     bool isRunning() const;
0044 
0045     void wakeUp();
0046 
0047     bool event(QEvent *event) override;
0048 
0049 public Q_SLOTS:
0050     void exit(int returnCode = 0);
0051     void quit();
0052 };
0053 
0054 Q_DECLARE_OPERATORS_FOR_FLAGS(QEventLoop::ProcessEventsFlags)
0055 
0056 class QEventLoopLockerPrivate;
0057 
0058 class QEventLoopLocker
0059 {
0060 public:
0061     Q_NODISCARD_CTOR Q_CORE_EXPORT QEventLoopLocker() noexcept;
0062     Q_NODISCARD_CTOR Q_CORE_EXPORT explicit QEventLoopLocker(QEventLoop *loop) noexcept;
0063     Q_NODISCARD_CTOR Q_CORE_EXPORT explicit QEventLoopLocker(QThread *thread) noexcept;
0064     Q_CORE_EXPORT ~QEventLoopLocker();
0065 
0066     Q_NODISCARD_CTOR QEventLoopLocker(QEventLoopLocker &&other) noexcept
0067         : p{std::exchange(other.p, 0)} {}
0068     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QEventLoopLocker)
0069 
0070     void swap(QEventLoopLocker &other) noexcept { std::swap(p, other.p); }
0071     friend void swap(QEventLoopLocker &lhs, QEventLoopLocker &rhs) noexcept { lhs.swap(rhs); }
0072 
0073 private:
0074     Q_DISABLE_COPY(QEventLoopLocker)
0075     friend class QEventLoopLockerPrivate;
0076 
0077     //
0078     // Private implementation details.
0079     // Do not call from public inline API!
0080     //
0081     enum class Type : quintptr {
0082         EventLoop,
0083         Thread,
0084         Application,
0085     };
0086     explicit QEventLoopLocker(void *ptr, Type t) noexcept;
0087     quintptr p;
0088     static constexpr quintptr TypeMask = 0x3;
0089     Type type() const { return Type(p & TypeMask); }
0090     void *pointer() const { return reinterpret_cast<void *>(p & ~TypeMask); }
0091     template <typename Func>
0092     void visit(Func func) const;
0093 };
0094 
0095 QT_END_NAMESPACE
0096 
0097 #endif // QEVENTLOOP_H