QDeadlineTimer Class
The QDeadlineTimer class marks a deadline in the future. More…
| Header | #include <QDeadlineTimer> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| typedef | Clock |
| enum | ForeverConstant |
Public Functions
| QDeadlineTimer(Qt::TimerType type = Qt::CoarseTimer) | |
| QDeadlineTimer(ForeverConstant, Qt::TimerType type = Qt::CoarseTimer) | |
| QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) | |
| QDeadlineTimer(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type = Qt::CoarseTimer) | |
| QDeadlineTimer(Clock::time_point deadline, Qt::TimerType type = Qt::CoarseTimer) | |
| void | swap(QDeadlineTimer &other) |
| bool | isForever() const |
| bool | hasExpired() const |
| Qt::TimerType | timerType() const |
| void | setTimerType(Qt::TimerType type) |
| qint64 | remainingTimeNSecs() const |
| qint64 | remainingTime() const |
| std::chrono::nanoseconds | remainingTimeAsDuration() const |
| void | setRemainingTime(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) |
| void | setRemainingTime(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type = Qt::CoarseTimer) |
| void | setPreciseRemainingTime(qint64 secs, qint64 nsecs = 0, Qt::TimerType type = Qt::CoarseTimer) |
| qint64 | deadline() const |
| qint64 | deadlineNSecs() const |
| void | setDeadline(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) |
| void | setDeadline(Clock::time_point deadline, Qt::TimerType type = Qt::CoarseTimer) |
| void | setPreciseDeadline(qint64 secs, qint64 nsecs = 0, Qt::TimerType type = Qt::CoarseTimer) |
| Clock::time_point | timePoint() const |
| QDeadlineTimer & | operator+=(qint64 msecs) |
| QDeadlineTimer & | operator-=(qint64 msecs) |
Static Public Members
| QDeadlineTimer | current(Qt::TimerType type = Qt::CoarseTimer) |
| QDeadlineTimer | addNSecs(QDeadlineTimer dt, qint64 nsecs) |
Detailed Description
A QDeadlineTimer stores a point in time, or the special value Forever that never expires. Use hasExpired() to test whether the deadline has passed and remainingTime() to find out how long is left, for example to pass a timeout to a wait function.
QDeadlineTimer deadline(500);
while (!deadline.hasExpired())
poll();
Deadlines can be compared and moved with + and -; a deadline that never expires compares greater than any other and is not changed by arithmetic.
See also QElapsedTimer.
Differences from Qt
The timer is based on std::chrono::steady_clock. The Qt::TimerType argument of the constructors and setters is stored but does not change the precision. Constructors and setters taking a std::chrono::time_point accept only the steady clock.
Member Type Documentation
typedef QDeadlineTimer::Clock
The clock that the timer reads, std::chrono::steady_clock.
enum QDeadlineTimer::ForeverConstant
| Constant | Description |
|---|---|
QDeadlineTimer::Forever | A deadline that never expires. |
Member Function Documentation
QDeadlineTimer::QDeadlineTimer(Qt::TimerType type = Qt::CoarseTimer)
Constructs a deadline that is already expired, with the timer type type.
See also setRemainingTime().
QDeadlineTimer::QDeadlineTimer(ForeverConstant, Qt::TimerType type = Qt::CoarseTimer)
Constructs a deadline that never expires, with the timer type type.
See also isForever().
QDeadlineTimer::QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer)
Constructs a deadline that expires in msecs milliseconds, with the timer type type. A negative value means the deadline never expires.
See also setRemainingTime().
template <class Rep, class Period>QDeadlineTimer::QDeadlineTimer(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type = Qt::CoarseTimer)
Constructs a deadline that expires after the duration remaining, with the timer type type. A zero or negative duration gives a deadline that has already expired, and duration::max() one that never expires.
See also setRemainingTime().
QDeadlineTimer::QDeadlineTimer(Clock::time_point deadline, Qt::TimerType type = Qt::CoarseTimer)
Constructs a deadline at the steady-clock time point deadline, with the timer type type.
See also setDeadline().
QDeadlineTimer QDeadlineTimer::addNSecs(QDeadlineTimer dt, qint64 nsecs)
Returns a deadline nsecs nanoseconds later than dt. A deadline that never expires is returned unchanged.
See also deadlineNSecs().
QDeadlineTimer QDeadlineTimer::current(Qt::TimerType type = Qt::CoarseTimer)
Returns a deadline that expired at the current time, with the timer type type.
See also hasExpired().
qint64 QDeadlineTimer::deadline() const
Returns the deadline in milliseconds since the reference point of the steady clock, the same reference that QElapsedTimer::msecsSinceReference() uses. A deadline that never expires returns the largest qint64.
See also deadlineNSecs() and setDeadline().
qint64 QDeadlineTimer::deadlineNSecs() const
Returns the deadline in nanoseconds since the reference point of the steady clock. A deadline that never expires returns the largest qint64.
See also deadline() and setPreciseDeadline().
bool QDeadlineTimer::hasExpired() const
Returns true if the deadline has passed; otherwise returns false. A deadline that never expires has not expired.
See also remainingTime().
bool QDeadlineTimer::isForever() const
Returns true if the deadline never expires; otherwise returns false.
QDeadlineTimer & QDeadlineTimer::operator+=(qint64 msecs)
Moves the deadline msecs milliseconds later and returns a reference to it. A deadline that never expires is not changed.
See also addNSecs().
QDeadlineTimer & QDeadlineTimer::operator-=(qint64 msecs)
Moves the deadline msecs milliseconds earlier and returns a reference to it. A deadline that never expires is not changed.
See also addNSecs().
qint64 QDeadlineTimer::remainingTime() const
Returns the time left until the deadline in milliseconds, rounded up, or -1 if the deadline never expires. The result is 0 once the deadline has passed.
See also remainingTimeNSecs().
std::chrono::nanoseconds QDeadlineTimer::remainingTimeAsDuration() const
Returns the time left until the deadline as a std::chrono::nanoseconds duration. The result is zero once the deadline has passed and std::chrono::nanoseconds::max() if it never expires.
See also remainingTimeNSecs().
qint64 QDeadlineTimer::remainingTimeNSecs() const
Returns the time left until the deadline in nanoseconds, or -1 if the deadline never expires. The result is 0 once the deadline has passed.
See also remainingTime().
void QDeadlineTimer::setDeadline(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer)
Sets the deadline to msecs milliseconds since the reference point of the steady clock and the timer type to type. The largest qint64 means the deadline never expires.
See also deadline() and setPreciseDeadline().
void QDeadlineTimer::setDeadline(Clock::time_point deadline, Qt::TimerType type = Qt::CoarseTimer)
This is an overloaded function.
Sets the deadline to the steady-clock time point deadline and the timer type to type.
void QDeadlineTimer::setPreciseDeadline(qint64 secs, qint64 nsecs = 0, Qt::TimerType type = Qt::CoarseTimer)
Sets the deadline to secs seconds and nsecs nanoseconds since the reference point of the steady clock and the timer type to type. The largest qint64 for secs means the deadline never expires.
See also setDeadline() and deadlineNSecs().
void QDeadlineTimer::setPreciseRemainingTime(qint64 secs, qint64 nsecs = 0, Qt::TimerType type = Qt::CoarseTimer)
Sets the deadline to secs seconds and nsecs nanoseconds from now and the timer type to type. A negative secs means the deadline never expires.
See also setRemainingTime().
void QDeadlineTimer::setRemainingTime(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer)
Sets the deadline to msecs milliseconds from now and the timer type to type. A negative value means the deadline never expires.
See also setPreciseRemainingTime().
template <class Rep, class Period>void QDeadlineTimer::setRemainingTime(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type = Qt::CoarseTimer)
This is an overloaded function.
Sets the deadline to the duration remaining from now and the timer type to type. A zero or negative duration makes the deadline expire now, and duration::max() makes it never expire.
void QDeadlineTimer::setTimerType(Qt::TimerType type)
Sets the timer type of this deadline to type. Nt records the type but always uses the precision of the steady clock.
See also timerType().
void QDeadlineTimer::swap(QDeadlineTimer &other)
Swaps this deadline with other.
Clock::time_point QDeadlineTimer::timePoint() const
Returns the deadline as a time point of the timer's clock. A deadline that never expires returns Clock::time_point::max().
See also isForever().
Qt::TimerType QDeadlineTimer::timerType() const
Returns the timer type of this deadline.
See also setTimerType().