Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qelapsedtimer.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 QELAPSEDTIMER_H
5#define QELAPSEDTIMER_H
6
7#include <QtCore/qcompare.h>
8#include <QtCore/qglobal.h>
9
10#include <chrono>
11
13
14class Q_CORE_EXPORT QElapsedTimer
15{
16public:
17 enum ClockType {
21 "Not supported anymore. Use PerformanceCounter instead."),
23 PerformanceCounter
24 };
25
26 // similar to std::chrono::*_clock
27 using Duration = std::chrono::nanoseconds;
28 using TimePoint = std::chrono::time_point<std::chrono::steady_clock, Duration>;
29
30 constexpr QElapsedTimer() = default;
31
32 static ClockType clockType() noexcept;
33 static bool isMonotonic() noexcept;
34
35 void start() noexcept;
36 qint64 restart() noexcept;
37 void invalidate() noexcept;
38 bool isValid() const noexcept;
39
40 Duration durationElapsed() const noexcept;
41 qint64 nsecsElapsed() const noexcept;
42 qint64 elapsed() const noexcept;
43 bool hasExpired(qint64 timeout) const noexcept;
44
45 qint64 msecsSinceReference() const noexcept;
46 Duration durationTo(const QElapsedTimer &other) const noexcept;
47 qint64 msecsTo(const QElapsedTimer &other) const noexcept;
48 qint64 secsTo(const QElapsedTimer &other) const noexcept;
49 friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept;
50
52 friend bool comparesEqual(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
53 {
54 return lhs.t1 == rhs.t1 && lhs.t2 == rhs.t2;
55 }
57
58 friend Qt::strong_ordering compareThreeWay(const QElapsedTimer &lhs,
59 const QElapsedTimer &rhs) noexcept
60 {
61 return Qt::compareThreeWay(lhs.t1, rhs.t1);
62 }
63
64#if defined(__cpp_lib_three_way_comparison)
65 friend std::strong_ordering
66 operator<=>(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
67 {
68 return compareThreeWay(lhs, rhs);
69 }
70#else
71 friend bool operator>(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
72 {
73 return is_gt(compareThreeWay(lhs, rhs));
74 }
75 friend bool operator<=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
76 {
77 return is_lteq(compareThreeWay(lhs, rhs));
78 }
79 friend bool operator>=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
80 {
81 return is_gteq(compareThreeWay(lhs, rhs));
82 }
83#endif // defined(__cpp_lib_three_way_comparison)
84 qint64 t1 = Q_INT64_C(0x8000000000000000);
85 qint64 t2 = Q_INT64_C(0x8000000000000000);
86};
87
89
90#endif // QELAPSEDTIMER_H
\inmodule QtCore
constexpr QElapsedTimer()=default
ClockType
This enum contains the different clock types that QElapsedTimer may use.
std::chrono::nanoseconds Duration
friend bool operator>(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
friend bool operator<=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
friend bool operator>=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
std::chrono::time_point< std::chrono::steady_clock, Duration > TimePoint
Combined button and popup list for selecting options.
Definition qcompare.h:63
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
#define Q_DECLARE_EQUALITY_COMPARABLE(...)
#define Q_DECL_ENUMERATOR_DEPRECATED_X(x)
bool comparesEqual(const QDir &lhs, const QDir &rhs)
Definition qdir.cpp:1819
static qint64 msecsTo(const QDateTime &from, const QDateTime &to)
GLbitfield GLuint64 timeout
[4]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLuint start
#define t2
static double elapsed(qint64 after, qint64 before)
long long qint64
Definition qtypes.h:60
#define Q_INT64_C(c)
Definition qtypes.h:57
Qt::weak_ordering compareThreeWay(const QUrl &lhs, const QUrl &rhs)
Definition qurl.cpp:3079
QSharedPointer< T > other(t)
[5]