![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qdeadlinetimer.h>
Public Types | |
enum class | ForeverConstant { Forever } |
\value Forever Used when creating a QDeadlineTimer to indicate the deadline should not expire More... | |
Public Member Functions | |
constexpr | QDeadlineTimer () noexcept=default |
constexpr | QDeadlineTimer (Qt::TimerType type_) noexcept |
Constructs an expired QDeadlineTimer object. | |
constexpr | QDeadlineTimer (ForeverConstant, Qt::TimerType type_=Qt::CoarseTimer) noexcept |
QDeadlineTimer objects created with ForeverConstant never expire. | |
QDeadlineTimer (qint64 msecs, Qt::TimerType type=Qt::CoarseTimer) noexcept | |
Constructs a QDeadlineTimer object with an expiry time of msecs msecs from the moment of the creation of this object, if msecs is positive. | |
void | swap (QDeadlineTimer &other) noexcept |
\memberswap{deadline timer} | |
constexpr bool | isForever () const noexcept |
Returns true if this QDeadlineTimer object never expires, false otherwise. | |
bool | hasExpired () const noexcept |
Returns true if this QDeadlineTimer object has expired, false if there remains time left. | |
Qt::TimerType | timerType () const noexcept |
Returns the timer type is active for this object. | |
void | setTimerType (Qt::TimerType type) |
Changes the timer type for this object to timerType. | |
qint64 | remainingTime () const noexcept |
Returns the remaining time in this QDeadlineTimer object in milliseconds. | |
qint64 | remainingTimeNSecs () const noexcept |
Returns the remaining time in this QDeadlineTimer object in nanoseconds. | |
void | setRemainingTime (qint64 msecs, Qt::TimerType type=Qt::CoarseTimer) noexcept |
Sets the remaining time for this QDeadlineTimer object to msecs milliseconds from now, if msecs has a positive value. | |
void | setPreciseRemainingTime (qint64 secs, qint64 nsecs=0, Qt::TimerType type=Qt::CoarseTimer) noexcept |
Sets the remaining time for this QDeadlineTimer object to secs seconds plus nsecs nanoseconds from now, if secs has a positive value. | |
qint64 | deadline () const noexcept Q_DECL_PURE_FUNCTION |
Returns the absolute time point for the deadline stored in QDeadlineTimer object, calculated in milliseconds relative to the reference clock, the same as QElapsedTimer::msecsSinceReference(). | |
qint64 | deadlineNSecs () const noexcept Q_DECL_PURE_FUNCTION |
Returns the absolute time point for the deadline stored in QDeadlineTimer object, calculated in nanoseconds relative to the reference clock, the same as QElapsedTimer::msecsSinceReference(). | |
void | setDeadline (qint64 msecs, Qt::TimerType timerType=Qt::CoarseTimer) noexcept |
Sets the deadline for this QDeadlineTimer object to be the msecs absolute time point, counted in milliseconds since the reference clock (the same as QElapsedTimer::msecsSinceReference()), and the timer type to timerType. | |
void | setPreciseDeadline (qint64 secs, qint64 nsecs=0, Qt::TimerType type=Qt::CoarseTimer) noexcept |
Sets the deadline for this QDeadlineTimer object to be secs seconds and nsecs nanoseconds since the reference clock epoch (the same as QElapsedTimer::msecsSinceReference()), and the timer type to timerType. | |
QDeadlineTimer & | operator+= (qint64 msecs) |
Extends this QDeadlineTimer object by msecs milliseconds and returns itself. | |
QDeadlineTimer & | operator-= (qint64 msecs) |
Shortens this QDeadlineTimer object by msecs milliseconds and returns itself. | |
template<class Clock, class Duration = typename Clock::duration> | |
QDeadlineTimer (std::chrono::time_point< Clock, Duration > deadline_, Qt::TimerType type_=Qt::CoarseTimer) | |
Constructs a QDeadlineTimer object with a deadline at deadline time point, converting from the clock source {Clock} to Qt's internal clock source (see QElapsedTimer::clockType()). | |
template<class Clock, class Duration = typename Clock::duration> | |
QDeadlineTimer & | operator= (std::chrono::time_point< Clock, Duration > deadline_) |
Assigns deadline_ to this deadline timer. | |
template<class Clock, class Duration = typename Clock::duration> | |
void | setDeadline (std::chrono::time_point< Clock, Duration > tp, Qt::TimerType type_=Qt::CoarseTimer) |
Sets this QDeadlineTimer to the deadline marked by deadline time point, converting from the clock source {Clock} to Qt's internal clock source (see QElapsedTimer::clockType()). | |
template<class Clock, class Duration = typename Clock::duration> | |
std::chrono::time_point< Clock, Duration > | deadline () const |
template<class Rep, class Period> | |
QDeadlineTimer (std::chrono::duration< Rep, Period > remaining, Qt::TimerType type_=Qt::CoarseTimer) | |
Constructs a QDeadlineTimer object with a remaining time of remaining. | |
template<class Rep, class Period> | |
QDeadlineTimer & | operator= (std::chrono::duration< Rep, Period > remaining) |
Sets this deadline timer to the remaining time. | |
template<class Rep, class Period> | |
void | setRemainingTime (std::chrono::duration< Rep, Period > remaining, Qt::TimerType type_=Qt::CoarseTimer) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
std::chrono::nanoseconds | remainingTimeAsDuration () const noexcept |
Returns the time remaining before the deadline. | |
Static Public Member Functions | |
static QDeadlineTimer | addNSecs (QDeadlineTimer dt, qint64 nsecs) noexcept Q_DECL_PURE_FUNCTION |
Returns a QDeadlineTimer object whose deadline is extended from dt's deadline by nsecs nanoseconds. | |
static QDeadlineTimer | current (Qt::TimerType timerType=Qt::CoarseTimer) noexcept |
Returns a QDeadlineTimer that is expired but is guaranteed to contain the current time. | |
Static Public Attributes | |
static constexpr ForeverConstant | Forever = ForeverConstant::Forever |
Friends | |
Q_CORE_EXPORT QDeadlineTimer | operator+ (QDeadlineTimer dt, qint64 msecs) |
Returns a QDeadlineTimer object whose deadline is msecs later than the deadline stored in dt. | |
QDeadlineTimer | operator+ (qint64 msecs, QDeadlineTimer dt) |
Returns a QDeadlineTimer object whose deadline is msecs later than the deadline stored in dt. | |
QDeadlineTimer | operator- (QDeadlineTimer dt, qint64 msecs) |
Returns a QDeadlineTimer object whose deadline is msecs before the deadline stored in dt. | |
qint64 | operator- (QDeadlineTimer dt1, QDeadlineTimer dt2) |
template<class Rep, class Period> | |
QDeadlineTimer | operator+ (QDeadlineTimer dt, std::chrono::duration< Rep, Period > value) |
template<class Rep, class Period> | |
QDeadlineTimer | operator+ (std::chrono::duration< Rep, Period > value, QDeadlineTimer dt) |
template<class Rep, class Period> | |
QDeadlineTimer | operator+= (QDeadlineTimer &dt, std::chrono::duration< Rep, Period > value) |
bool | comparesEqual (const QDeadlineTimer &lhs, const QDeadlineTimer &rhs) noexcept |
Qt::strong_ordering | compareThreeWay (const QDeadlineTimer &lhs, const QDeadlineTimer &rhs) noexcept |
\inmodule QtCore
The QDeadlineTimer class marks a deadline in the future.
\reentrant
\compares strong
The QDeadlineTimer class is usually used to calculate future deadlines and verify whether the deadline has expired. QDeadlineTimer can also be used for deadlines without expiration ("forever"). It forms a counterpart to QElapsedTimer, which calculates how much time has elapsed since QElapsedTimer::start() was called.
QDeadlineTimer provides a more convenient API compared to QElapsedTimer::hasExpired().
The typical use-case for the class is to create a QDeadlineTimer before the operation in question is started, and then use remainingTime() or hasExpired() to determine whether to continue trying the operation. QDeadlineTimer objects can be passed to functions being called to execute this operation so they know how long to still operate.
Many QDeadlineTimer functions deal with time out values, which all are measured in milliseconds. There are two special values, the same as many other Qt functions named {waitFor} or similar:
\list
Definition at line 22 of file qdeadlinetimer.h.
|
strong |
\value Forever Used when creating a QDeadlineTimer to indicate the deadline should not expire
Enumerator | |
---|---|
Forever |
Definition at line 25 of file qdeadlinetimer.h.
|
constexprdefaultnoexcept |
|
inlineexplicitconstexprnoexcept |
Constructs an expired QDeadlineTimer object.
For this object, remainingTime() will return 0. If timerType is not set, then the object will use the \l{Qt::CoarseTimer}{coarse} \l{QDeadlineTimer#Timer types}{timer type}.
The timer type timerType may be ignored, since the timer is already expired. Similarly, for optimization purposes, this function will not attempt to obtain the current time and will use a value known to be in the past. Therefore, deadline() may return an unexpected value and this object cannot be used in calculation of how long it is overdue. If that functionality is required, use QDeadlineTimer::current().
Definition at line 29 of file qdeadlinetimer.h.
|
inlineconstexprnoexcept |
QDeadlineTimer objects created with ForeverConstant never expire.
For such objects, remainingTime() will return -1, deadline() will return the maximum value, and isForever() will return true.
The timer type timerType may be ignored, since the timer will never expire.
Definition at line 31 of file qdeadlinetimer.h.
|
explicitnoexcept |
Constructs a QDeadlineTimer object with an expiry time of msecs msecs from the moment of the creation of this object, if msecs is positive.
If msecs is zero, this QDeadlineTimer will be marked as expired, causing remainingTime() to return zero and deadline() to return an indeterminate time point in the past. If msecs is negative, the timer will be set to never expire, causing remainingTime() to return -1 and deadline() to return the maximum value.
The QDeadlineTimer object will be constructed with the specified timer type.
For optimization purposes, if msecs is zero, this function may skip obtaining the current time and may instead use a value known to be in the past. If that happens, deadline() may return an unexpected value and this object cannot be used in calculation of how long it is overdue. If that functionality is required, use QDeadlineTimer::current() and add time to it.
Definition at line 190 of file qdeadlinetimer.cpp.
|
inline |
Constructs a QDeadlineTimer object with a deadline at deadline time point, converting from the clock source {Clock} to Qt's internal clock source (see QElapsedTimer::clockType()).
If deadline is in the past, this QDeadlineTimer object is set to expired, whereas if deadline is equal to {Duration::max()}, then this object is set to never expire.
The QDeadlineTimer object will be constructed with the specified timer type.
Definition at line 74 of file qdeadlinetimer.h.
|
inline |
Constructs a QDeadlineTimer object with a remaining time of remaining.
If remaining is zero or negative, this QDeadlineTimer object will be mark as expired, whereas if remaining is equal to {duration::max()}, the object will be set to never expire.
The QDeadlineTimer object will be constructed with the specified timer type.
This constructor can be used with C++14's user-defined literals for time, such as in:
For optimization purposes, if remaining is zero or negative, this function may skip obtaining the current time and may instead use a value known to be in the past. If that happens, deadline() may return an unexpected value and this object cannot be used in calculation of how long it is overdue. If that functionality is required, use QDeadlineTimer::current() and add time to it.
Definition at line 89 of file qdeadlinetimer.h.
|
staticnoexcept |
Returns a QDeadlineTimer object whose deadline is extended from dt's deadline by nsecs nanoseconds.
If dt was set to never expire, this function returns a QDeadlineTimer that will not expire either.
Definition at line 565 of file qdeadlinetimer.cpp.
|
staticnoexcept |
Returns a QDeadlineTimer that is expired but is guaranteed to contain the current time.
Objects created by this function can participate in the calculation of how long a timer is overdue, using the deadline() function.
The QDeadlineTimer object will be constructed with the specified timerType.
Definition at line 583 of file qdeadlinetimer.cpp.
std::chrono::time_point< Clock, Duration > QDeadlineTimer::deadline | ( | ) | const |
Definition at line 150 of file qdeadlinetimer.h.
|
noexcept |
Returns the absolute time point for the deadline stored in QDeadlineTimer object, calculated in milliseconds relative to the reference clock, the same as QElapsedTimer::msecsSinceReference().
The value will be in the past if this QDeadlineTimer has expired.
If this QDeadlineTimer never expires, this function returns {std::numeric_limits<qint64>::max()}.
This function can be used to calculate the amount of time a timer is overdue, by subtracting QDeadlineTimer::current() or QElapsedTimer::msecsSinceReference(), as in the following example:
Definition at line 475 of file qdeadlinetimer.cpp.
|
noexcept |
Returns the absolute time point for the deadline stored in QDeadlineTimer object, calculated in nanoseconds relative to the reference clock, the same as QElapsedTimer::msecsSinceReference().
The value will be in the past if this QDeadlineTimer has expired.
If this QDeadlineTimer never expires or the number of nanoseconds until the deadline can't be accommodated in the return type, this function returns {std::numeric_limits<qint64>::max()}.
This function can be used to calculate the amount of time a timer is overdue, by subtracting QDeadlineTimer::current(), as in the following example:
Definition at line 507 of file qdeadlinetimer.cpp.
|
noexcept |
Returns true if this QDeadlineTimer object has expired, false if there remains time left.
For objects that have expired, remainingTime() will return zero and deadline() will return a time point in the past.
QDeadlineTimer objects created with the \l {ForeverConstant} never expire and this function always returns false for them.
Definition at line 363 of file qdeadlinetimer.cpp.
|
inlineconstexprnoexcept |
Returns true if this QDeadlineTimer object never expires, false otherwise.
For timers that never expire, remainingTime() always returns -1 and deadline() returns the maximum value.
Definition at line 38 of file qdeadlinetimer.h.
|
inline |
Extends this QDeadlineTimer object by msecs milliseconds and returns itself.
If this object is set to never expire, this function does nothing.
To add times of precision greater than 1 millisecond, use addNSecs().
Definition at line 68 of file qdeadlinetimer.h.
|
inline |
Shortens this QDeadlineTimer object by msecs milliseconds and returns itself.
If this object is set to never expire, this function does nothing.
To subtract times of precision greater than 1 millisecond, use addNSecs().
Definition at line 70 of file qdeadlinetimer.h.
|
inline |
Sets this deadline timer to the remaining time.
Definition at line 94 of file qdeadlinetimer.h.
|
inline |
Assigns deadline_ to this deadline timer.
Definition at line 78 of file qdeadlinetimer.h.
|
noexcept |
Returns the remaining time in this QDeadlineTimer object in milliseconds.
If the timer has already expired, this function will return zero and it is not possible to obtain the amount of time overdue with this function (to do that, see deadline()). If the timer was set to never expire, this function returns -1.
This function is suitable for use in Qt APIs that take a millisecond timeout, such as the many \l QIODevice waitFor
functions or the timed lock functions in \l QMutex, \l QWaitCondition, \l QSemaphore, or \l QReadWriteLock. For example:
Definition at line 412 of file qdeadlinetimer.cpp.
|
inlinenoexcept |
Returns the time remaining before the deadline.
Definition at line 107 of file qdeadlinetimer.h.
|
noexcept |
Returns the remaining time in this QDeadlineTimer object in nanoseconds.
If the timer has already expired, this function will return zero and it is not possible to obtain the amount of time overdue with this function. If the timer was set to never expire, this function returns -1.
Definition at line 429 of file qdeadlinetimer.cpp.
|
noexcept |
Sets the deadline for this QDeadlineTimer object to be the msecs absolute time point, counted in milliseconds since the reference clock (the same as QElapsedTimer::msecsSinceReference()), and the timer type to timerType.
If the value is in the past, this QDeadlineTimer will be marked as expired.
If msecs is {std::numeric_limits<qint64>::max()} or the deadline is beyond a representable point in the future, this QDeadlineTimer will be set to never expire.
Definition at line 528 of file qdeadlinetimer.cpp.
void QDeadlineTimer::setDeadline | ( | std::chrono::time_point< Clock, Duration > | deadline, |
Qt::TimerType | type = Qt::CoarseTimer ) |
Sets this QDeadlineTimer to the deadline marked by deadline time point, converting from the clock source {Clock} to Qt's internal clock source (see QElapsedTimer::clockType()).
If deadline is in the past, this QDeadlineTimer object is set to expired, whereas if deadline is equal to {Duration::max()}, then this object is set to never expire.
The timer type for this QDeadlineTimer object will be set to the specified type.
Definition at line 163 of file qdeadlinetimer.h.
|
noexcept |
Sets the deadline for this QDeadlineTimer object to be secs seconds and nsecs nanoseconds since the reference clock epoch (the same as QElapsedTimer::msecsSinceReference()), and the timer type to timerType.
If the value is in the past, this QDeadlineTimer will be marked as expired.
If secs or nsecs is {std::numeric_limits<qint64>::max()}, this QDeadlineTimer will be set to never expire. If nsecs is more than 1 billion nanoseconds (1 second), then secs will be adjusted accordingly.
Definition at line 551 of file qdeadlinetimer.cpp.
|
noexcept |
Sets the remaining time for this QDeadlineTimer object to secs seconds plus nsecs nanoseconds from now, if secs has a positive value.
If secs is negative, this QDeadlineTimer will be set it to never expire (this behavior does not apply to nsecs). If both parameters are zero, this QDeadlineTimer will be marked as expired.
For optimization purposes, if both secs and nsecs are zero, this function may skip obtaining the current time and may instead use a value known to be in the past. If that happens, deadline() may return an unexpected value and this object cannot be used in calculation of how long it is overdue. If that functionality is required, use QDeadlineTimer::current() and add time to it.
The timer type for this QDeadlineTimer object will be set to the specified timerType.
Definition at line 307 of file qdeadlinetimer.cpp.
|
noexcept |
Sets the remaining time for this QDeadlineTimer object to msecs milliseconds from now, if msecs has a positive value.
If msecs is zero, this QDeadlineTimer object will be marked as expired, whereas a negative value will set it to never expire.
For optimization purposes, if msecs is zero, this function may skip obtaining the current time and may instead use a value known to be in the past. If that happens, deadline() may return an unexpected value and this object cannot be used in calculation of how long it is overdue. If that functionality is required, use QDeadlineTimer::current() and add time to it.
The timer type for this QDeadlineTimer object will be set to the specified timerType.
Definition at line 271 of file qdeadlinetimer.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the remaining time for this QDeadlineTimer object to remaining. If remaining is zero or negative, this QDeadlineTimer object will be mark as expired, whereas if remaining is equal to {duration::max()}, the object will be set to never expire.
The timer type for this QDeadlineTimer object will be set to the specified type.
This function can be used with C++14's user-defined literals for time, such as in:
Definition at line 98 of file qdeadlinetimer.h.
void QDeadlineTimer::setTimerType | ( | Qt::TimerType | timerType | ) |
Changes the timer type for this object to timerType.
The behavior for each possible value of timerType is operating-system dependent. Qt::PreciseTimer will use the most precise timer that Qt can find, with resolution of 1 millisecond or better, whereas QDeadlineTimer will try to use a more coarse timer for Qt::CoarseTimer and Qt::VeryCoarseTimer.
Definition at line 391 of file qdeadlinetimer.cpp.
|
inlinenoexcept |
\memberswap{deadline timer}
Definition at line 35 of file qdeadlinetimer.h.
|
inlinenoexcept |
Returns the timer type is active for this object.
Definition at line 42 of file qdeadlinetimer.h.
|
friend |
Definition at line 128 of file qdeadlinetimer.h.
|
friend |
Definition at line 133 of file qdeadlinetimer.h.
|
friend |
Returns a QDeadlineTimer object whose deadline is msecs later than the deadline stored in dt.
If dt is set to never expire, this function returns a QDeadlineTimer that does not expire either.
To add times of precision greater than 1 millisecond, use addNSecs().
Definition at line 683 of file qdeadlinetimer.cpp.
|
friend |
Definition at line 118 of file qdeadlinetimer.h.
|
friend |
Returns a QDeadlineTimer object whose deadline is msecs later than the deadline stored in dt.
If dt is set to never expire, this function returns a QDeadlineTimer that does not expire either.
To add times of precision greater than 1 millisecond, use addNSecs().
Definition at line 62 of file qdeadlinetimer.h.
|
friend |
Definition at line 121 of file qdeadlinetimer.h.
|
friend |
Definition at line 124 of file qdeadlinetimer.h.
|
friend |
Returns a QDeadlineTimer object whose deadline is msecs before the deadline stored in dt.
If dt is set to never expire, this function returns a QDeadlineTimer that does not expire either.
To subtract times of precision greater than 1 millisecond, use addNSecs().
Definition at line 64 of file qdeadlinetimer.h.
|
friend |
Definition at line 66 of file qdeadlinetimer.h.
|
staticconstexpr |
Definition at line 26 of file qdeadlinetimer.h.