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
QDeadlineTimer Class Reference

\inmodule QtCore More...

#include <qdeadlinetimer.h>

+ Collaboration diagram for QDeadlineTimer:

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
 Swaps this deadline timer with the other 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.
 
QDeadlineTimeroperator+= (qint64 msecs)
 Extends this QDeadlineTimer object by msecs milliseconds and returns itself.
 
QDeadlineTimeroperator-= (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>
QDeadlineTimeroperator= (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 >
QDeadlineTimeroperator= (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
 

Detailed Description

\inmodule QtCore

The QDeadlineTimer class marks a deadline in the future.

Since
5.8

\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

  • 0: no time left, expired
  • -1: infinite time left, timer never expires \endlist

Definition at line 22 of file qdeadlinetimer.h.

Member Enumeration Documentation

◆ ForeverConstant

\value Forever Used when creating a QDeadlineTimer to indicate the deadline should not expire

Enumerator
Forever 

Definition at line 25 of file qdeadlinetimer.h.

Constructor & Destructor Documentation

◆ QDeadlineTimer() [1/6]

QDeadlineTimer::QDeadlineTimer ( )
constexprdefaultnoexcept

◆ QDeadlineTimer() [2/6]

QDeadlineTimer::QDeadlineTimer ( Qt::TimerType timerType)
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().

See also
hasExpired(), remainingTime(), Qt::TimerType, current()

Definition at line 29 of file qdeadlinetimer.h.

◆ QDeadlineTimer() [3/6]

QDeadlineTimer::QDeadlineTimer ( ForeverConstant ,
Qt::TimerType timerType = Qt::CoarseTimer )
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.

See also
ForeverConstant, hasExpired(), isForever(), remainingTime(), timerType()

Definition at line 31 of file qdeadlinetimer.h.

◆ QDeadlineTimer() [4/6]

QDeadlineTimer::QDeadlineTimer ( qint64 msecs,
Qt::TimerType type = Qt::CoarseTimer )
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.

Note
Prior to Qt 6.6, the only value that caused the timer to never expire was -1.
See also
hasExpired(), isForever(), remainingTime(), setRemainingTime()

Definition at line 190 of file qdeadlinetimer.cpp.

References setRemainingTime().

+ Here is the call graph for this function:

◆ QDeadlineTimer() [5/6]

template<class Clock , class Duration = typename Clock::duration>
template< class Clock, class Duration > QDeadlineTimer::QDeadlineTimer ( std::chrono::time_point< Clock, Duration > deadline,
Qt::TimerType type = Qt::CoarseTimer )
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.

See also
hasExpired(), isForever(), remainingTime(), setDeadline()

Definition at line 74 of file qdeadlinetimer.h.

◆ QDeadlineTimer() [6/6]

template<class Rep , class Period >
template< class Rep, class Period > QDeadlineTimer::QDeadlineTimer ( std::chrono::duration< Rep, Period > remaining,
Qt::TimerType type = Qt::CoarseTimer )
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:

using namespace std::chrono_literals;

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.

See also
hasExpired(), isForever(), remainingTime(), setRemainingTime()

Definition at line 89 of file qdeadlinetimer.h.

References setRemainingTime().

+ Here is the call graph for this function:

Member Function Documentation

◆ addNSecs()

QDeadlineTimer QDeadlineTimer::addNSecs ( QDeadlineTimer dt,
qint64 nsecs )
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.

Note
if dt was created as expired, its deadline is indeterminate and adding an amount of time may or may not cause it to become unexpired.

Definition at line 565 of file qdeadlinetimer.cpp.

References add_saturate().

+ Here is the call graph for this function:

◆ current()

QDeadlineTimer QDeadlineTimer::current ( Qt::TimerType timerType = Qt::CoarseTimer)
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.

Referenced by fallback_fill(), formatLogMessage(), getticks(), hasExpired(), and if().

+ Here is the caller graph for this function:

◆ deadline() [1/2]

template<class Clock , class Duration >
std::chrono::time_point< Clock, Duration > QDeadlineTimer::deadline ( ) const

Definition at line 150 of file qdeadlinetimer.h.

References deadlineNSecs().

+ Here is the call graph for this function:

◆ deadline() [2/2]

qint64 QDeadlineTimer::deadline ( ) const
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:

if (realTimeLeft != (std::numeric_limits<qint64>::max)()) {
// or:
//QElapsedTimer timer;
//timer.start();
//realTimeLeft -= timer.msecsSinceReference();
}
Note
Timers that were created as expired have an indetermine time point in the past as their deadline, so the above calculation may not work.
See also
remainingTime(), deadlineNSecs(), setDeadline()

Definition at line 475 of file qdeadlinetimer.cpp.

References isForever().

Referenced by QtLinuxFutex::futexWait(), and qt_abstime_for_timeout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deadlineNSecs()

qint64 QDeadlineTimer::deadlineNSecs ( ) const
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:

if (realTimeLeft != std::numeric_limits<qint64>::max())
realTimeLeft -= QDeadlineTimer::current().deadlineNSecs();
Note
Timers that were created as expired have an indetermine time point in the past as their deadline, so the above calculation may not work.
See also
remainingTime(), deadlineNSecs()

Definition at line 507 of file qdeadlinetimer.cpp.

References isForever().

+ Here is the call graph for this function:

◆ hasExpired()

bool QDeadlineTimer::hasExpired ( ) const
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.

See also
isForever(), remainingTime()

Definition at line 363 of file qdeadlinetimer.cpp.

References current(), isForever(), and timerType().

Referenced by QV4::MarkStack::drain(), executeOperation(), QEventLoop::processEvents(), QCoreApplication::processEvents(), QTest::qWait(), QQmlInstantiationInterrupt::shouldInterrupt(), QSingleShotTimer::startTimerForReceiver(), QNetworkAccessCache::timerEvent(), QV4::GCStateMachine::transition(), QWaitConditionPrivate::wait(), QAbstractSocket::waitForConnected(), and QAbstractSocket::waitForReadyRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isForever()

bool QDeadlineTimer::isForever ( ) const
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.

See also
ForeverConstant, hasExpired(), remainingTime()

Definition at line 38 of file qdeadlinetimer.h.

Referenced by deadline(), deadlineNSecs(), hasExpired(), qt_safe_poll(), QTest::qWait(), remainingTime(), remainingTimeNSecs(), QWaitConditionPrivate::wait(), QWaitConditionPrivate::wait(), and QAbstractSocket::waitForConnected().

+ Here is the caller graph for this function:

◆ operator+=()

QDeadlineTimer & QDeadlineTimer::operator+= ( qint64 msecs)
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.

◆ operator-=()

QDeadlineTimer & QDeadlineTimer::operator-= ( qint64 msecs)
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.

◆ operator=() [1/2]

template<class Rep , class Period >
template< class Rep, class Period > QDeadlineTimer & QDeadlineTimer::operator= ( std::chrono::duration< Rep, Period > remaining)
inline

Sets this deadline timer to the remaining time.

Definition at line 94 of file qdeadlinetimer.h.

References setRemainingTime().

+ Here is the call graph for this function:

◆ operator=() [2/2]

template<class Clock , class Duration = typename Clock::duration>
template< class Clock, class Duration > QDeadlineTimer & QDeadlineTimer::operator= ( std::chrono::time_point< Clock, Duration > deadline_)
inline

Assigns deadline_ to this deadline timer.

Definition at line 78 of file qdeadlinetimer.h.

◆ remainingTime()

qint64 QDeadlineTimer::remainingTime ( ) const
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:

See also
remainingTimeNSecs(), isForever(), hasExpired()

Definition at line 412 of file qdeadlinetimer.cpp.

References isForever(), and remainingTimeNSecs().

Referenced by QSocks5SocketEngine::close(), executeOperation(), QtWindowsFutex::futexWait(), QWaitConditionPrivate::wait(), QSocks5SocketEnginePrivate::waitForConnected(), QHttpSocketEngine::waitForProtocolHandshake(), QHttpSocketEngine::waitForRead(), QSocks5SocketEngine::waitForRead(), QHttpSocketEngine::waitForWrite(), and QSocks5SocketEngine::waitForWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remainingTimeAsDuration()

std::chrono::nanoseconds QDeadlineTimer::remainingTimeAsDuration ( ) const
inlinenoexcept

Returns the time remaining before the deadline.

Definition at line 107 of file qdeadlinetimer.h.

Referenced by qt_safe_poll(), QTest::qWait(), QSingleShotTimer::startTimerForReceiver(), QAbstractSocket::waitForConnected(), QSocks5SocketEngine::waitForRead(), and QSocks5SocketEngine::waitForWrite().

+ Here is the caller graph for this function:

◆ remainingTimeNSecs()

qint64 QDeadlineTimer::remainingTimeNSecs ( ) const
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.

See also
remainingTime(), isForever(), hasExpired()

Definition at line 429 of file qdeadlinetimer.cpp.

References isForever().

Referenced by remainingTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDeadline() [1/2]

void QDeadlineTimer::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.

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.

See also
setPreciseDeadline(), deadline(), deadlineNSecs(), setRemainingTime()

Definition at line 528 of file qdeadlinetimer.cpp.

References add_saturate().

+ Here is the call graph for this function:

◆ setDeadline() [2/2]

template<class Clock , class Duration >
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.

See also
hasExpired(), isForever(), remainingTime(),

Definition at line 163 of file qdeadlinetimer.h.

◆ setPreciseDeadline()

void QDeadlineTimer::setPreciseDeadline ( qint64 secs,
qint64 nsecs = 0,
Qt::TimerType timerType = 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.

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.

See also
setDeadline(), deadline(), deadlineNSecs(), setRemainingTime()

Definition at line 551 of file qdeadlinetimer.cpp.

References add_saturate().

+ Here is the call graph for this function:

◆ setPreciseRemainingTime()

void QDeadlineTimer::setPreciseRemainingTime ( qint64 secs,
qint64 nsecs = 0,
Qt::TimerType timerType = 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.

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.

Note
Prior to Qt 6.6, the only condition that caused the timer to never expire was when secs was -1.
See also
setRemainingTime(), hasExpired(), isForever(), remainingTime()

Definition at line 307 of file qdeadlinetimer.cpp.

References add_saturate().

+ Here is the call graph for this function:

◆ setRemainingTime() [1/2]

void QDeadlineTimer::setRemainingTime ( qint64 msecs,
Qt::TimerType timerType = Qt::CoarseTimer )
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.

Note
Prior to Qt 6.6, the only value that caused the timer to never expire was -1.
See also
setPreciseRemainingTime(), hasExpired(), isForever(), remainingTime()

Definition at line 271 of file qdeadlinetimer.cpp.

References add_saturate().

+ Here is the call graph for this function:

◆ setRemainingTime() [2/2]

template<class Rep , class Period >
template< class Rep, class Period > void QDeadlineTimer::setRemainingTime ( std::chrono::duration< Rep, Period > remaining,
Qt::TimerType type = Qt::CoarseTimer )
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:

using namespace std::chrono_literals;
Note
Qt detects the necessary C++14 compiler support by way of the feature test recommendations from \l{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations} {C++ Committee's Standing Document 6}.
See also
setDeadline(), remainingTime(), hasExpired(), isForever()

Definition at line 98 of file qdeadlinetimer.h.

◆ setTimerType()

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.

See also
Qt::TimerType

Definition at line 391 of file qdeadlinetimer.cpp.

References timerType().

+ Here is the call graph for this function:

◆ swap()

void QDeadlineTimer::swap ( QDeadlineTimer & other)
inlinenoexcept

Swaps this deadline timer with the other deadline timer.

Definition at line 35 of file qdeadlinetimer.h.

References other().

+ Here is the call graph for this function:

◆ timerType()

Qt::TimerType QDeadlineTimer::timerType ( ) const
inlinenoexcept

Returns the timer type is active for this object.

See also
setTimerType()

Definition at line 42 of file qdeadlinetimer.h.

Referenced by hasExpired(), and setTimerType().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ comparesEqual

bool comparesEqual ( const QDeadlineTimer & lhs,
const QDeadlineTimer & rhs )
friend

Definition at line 128 of file qdeadlinetimer.h.

◆ compareThreeWay

Qt::strong_ordering compareThreeWay ( const QDeadlineTimer & lhs,
const QDeadlineTimer & rhs )
friend

Definition at line 133 of file qdeadlinetimer.h.

◆ operator+ [1/4]

QDeadlineTimer QDeadlineTimer::operator+ ( QDeadlineTimer dt,
qint64 msecs )
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.

◆ operator+ [2/4]

template<class Rep , class Period >
QDeadlineTimer operator+ ( QDeadlineTimer dt,
std::chrono::duration< Rep, Period > value )
friend

Definition at line 118 of file qdeadlinetimer.h.

◆ operator+ [3/4]

QDeadlineTimer QDeadlineTimer::operator+ ( qint64 msecs,
QDeadlineTimer dt )
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.

◆ operator+ [4/4]

template<class Rep , class Period >
QDeadlineTimer operator+ ( std::chrono::duration< Rep, Period > value,
QDeadlineTimer dt )
friend

Definition at line 121 of file qdeadlinetimer.h.

◆ operator+=

template<class Rep , class Period >
QDeadlineTimer operator+= ( QDeadlineTimer & dt,
std::chrono::duration< Rep, Period > value )
friend

Definition at line 124 of file qdeadlinetimer.h.

◆ operator- [1/2]

QDeadlineTimer QDeadlineTimer::operator- ( QDeadlineTimer dt,
qint64 msecs )
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.

◆ operator- [2/2]

qint64 operator- ( QDeadlineTimer dt1,
QDeadlineTimer dt2 )
friend

Definition at line 66 of file qdeadlinetimer.h.

Member Data Documentation

◆ Forever


The documentation for this class was generated from the following files: