Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qdeadlinetimer.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 Intel Corporation.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qdeadlinetimer.h"
6
#
include
"private/qnumeric_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
QT_IMPL_METATYPE_EXTERN(QDeadlineTimer)
11
12
using
namespace
std::chrono;
13
14
namespace
{
15
struct
TimeReference : std::numeric_limits<qint64>
16
{
17
static
constexpr
qint64 Min = min();
18
static
constexpr
qint64 Max = max();
19
};
20
}
21
22
template
<
typename
Duration1,
typename
... Durations>
23
static
qint64
add_saturate
(qint64 t1, Duration1 dur, Durations... extra)
24
{
25
qint64 v = dur.count();
26
qint64 saturated = std::numeric_limits<qint64>::max();
27
if
(v < 0)
28
saturated = std::numeric_limits<qint64>::min();
29
30
// convert to nanoseconds with saturation
31
using
Ratio = std::ratio_divide<
typename
Duration1::period, nanoseconds::period>;
32
static_assert
(Ratio::den == 1,
"sub-multiples of nanosecond are not supported"
);
33
if
(qMulOverflow<Ratio::num>(v, &v))
34
return
saturated;
35
36
qint64 r;
37
if
(qAddOverflow(t1, v, &r))
38
return
saturated;
39
if
constexpr
(
sizeof
...(Durations)) {
40
// chain more additions
41
return
add_saturate(r, extra...);
42
}
43
return
r;
44
}
45
46
/*!
47
\class QDeadlineTimer
48
\inmodule QtCore
49
\brief The QDeadlineTimer class marks a deadline in the future.
50
\since 5.8
51
52
\reentrant
53
\ingroup tools
54
55
\compares strong
56
57
The QDeadlineTimer class is usually used to calculate future deadlines and
58
verify whether the deadline has expired. QDeadlineTimer can also be used
59
for deadlines without expiration ("forever"). It forms a counterpart to
60
QElapsedTimer, which calculates how much time has elapsed since
61
QElapsedTimer::start() was called.
62
63
QDeadlineTimer provides a more convenient API compared to
64
QElapsedTimer::hasExpired().
65
66
The typical use-case for the class is to create a QDeadlineTimer before the
67
operation in question is started, and then use remainingTime() or
68
hasExpired() to determine whether to continue trying the operation.
69
QDeadlineTimer objects can be passed to functions being called to execute
70
this operation so they know how long to still operate.
71
72
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 0
73
74
Many QDeadlineTimer functions deal with time out values, which all are
75
measured in milliseconds. There are two special values, the same as many
76
other Qt functions named \c{waitFor} or similar:
77
78
\list
79
\li 0: no time left, expired
80
\li -1: infinite time left, timer never expires
81
\endlist
82
83
\section1 Reference Clocks
84
85
QDeadlineTimer will use the same clock as QElapsedTimer (see
86
QElapsedTimer::clockType() and QElapsedTimer::isMonotonic()).
87
88
\section1 Timer types
89
90
Like QTimer and QChronoTimer, QDeadlineTimer can select among
91
different levels of coarseness on the timers. You can select
92
precise timing by passing Qt::PreciseTimer to the functions that
93
set of change the timer, or you can select coarse timing by passing
94
Qt::CoarseTimer. Qt::VeryCoarseTimer is currently interpreted the same
95
way as Qt::CoarseTimer.
96
97
This feature is dependent on support from the operating system: if the OS
98
does not support a coarse timer functionality, then QDeadlineTimer will
99
behave like Qt::PreciseTimer was passed.
100
101
QDeadlineTimer defaults to Qt::CoarseTimer because on operating systems
102
that do support coarse timing, making timing calls to that clock source is
103
often much more efficient. The level of coarseness depends on the
104
operating system, but should be in the order of a couple of milliseconds.
105
106
\section1 \c{std::chrono} Compatibility
107
108
QDeadlineTimer is compatible with the \c{std::chrono} API from C++11 and
109
can be constructed from or compared to both \c{std::chrono::duration} and
110
\c{std::chrono::time_point} objects. In addition, it is fully compatible
111
with the \l{chrono_literals Symbol Index}{time literals
112
from C++14}, which allow one to write code such as:
113
114
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 1
115
116
As can be seen in the example above, QDeadlineTimer offers a templated
117
version of remainingTime() and deadline() that can be used to return
118
\c{std::chrono} objects.
119
120
Note that comparing to \c{time_point} is not as efficient as comparing to
121
\c{duration}, since QDeadlineTimer may need to convert from its own
122
internal clock source to the clock source used by the \c{time_point} object.
123
Also note that, due to this conversion, the deadlines will not be precise,
124
so the following code is not expected to compare equally:
125
126
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 2
127
128
\sa QTime, QChronoTimer, QElapsedTimer, Qt::TimerType
129
*/
130
131
/*!
132
\enum QDeadlineTimer::ForeverConstant
133
134
\value Forever Used when creating a QDeadlineTimer to indicate the
135
deadline should not expire
136
*/
137
138
/*!
139
\fn QDeadlineTimer::QDeadlineTimer()
140
\fn QDeadlineTimer::QDeadlineTimer(Qt::TimerType timerType)
141
142
Constructs an expired QDeadlineTimer object. For this object,
143
remainingTime() will return 0. If \a timerType is not set, then the object
144
will use the \l{Qt::CoarseTimer}{coarse} \l{QDeadlineTimer#Timer types}{timer type}.
145
146
The timer type \a timerType may be ignored, since the timer is already
147
expired. Similarly, for optimization purposes, this function will not
148
attempt to obtain the current time and will use a value known to be in the
149
past. Therefore, deadline() may return an unexpected value and this object
150
cannot be used in calculation of how long it is overdue. If that
151
functionality is required, use QDeadlineTimer::current().
152
153
\sa hasExpired(), remainingTime(), Qt::TimerType, current()
154
*/
155
156
/*!
157
\fn QDeadlineTimer::QDeadlineTimer(ForeverConstant, Qt::TimerType timerType)
158
159
QDeadlineTimer objects created with ForeverConstant never expire.
160
For such objects, remainingTime() will return -1, deadline() will return the
161
maximum value, and isForever() will return true.
162
163
The timer type \a timerType may be ignored, since the timer will never
164
expire.
165
166
\sa ForeverConstant, hasExpired(), isForever(), remainingTime(), timerType()
167
*/
168
169
/*!
170
Constructs a QDeadlineTimer object with an expiry time of \a msecs msecs
171
from the moment of the creation of this object, if msecs is positive. If \a
172
msecs is zero, this QDeadlineTimer will be marked as expired, causing
173
remainingTime() to return zero and deadline() to return an indeterminate
174
time point in the past. If \a msecs is negative, the timer will be set to never
175
expire, causing remainingTime() to return -1 and deadline() to return the
176
maximum value.
177
178
The QDeadlineTimer object will be constructed with the specified timer \a type.
179
180
For optimization purposes, if \a msecs is zero, this function may skip
181
obtaining the current time and may instead use a value known to be in the
182
past. If that happens, deadline() may return an unexpected value and this
183
object cannot be used in calculation of how long it is overdue. If that
184
functionality is required, use QDeadlineTimer::current() and add time to
185
it.
186
187
\note Prior to Qt 6.6, the only value that caused the timer to never expire
188
was -1.
189
190
\sa hasExpired(), isForever(), remainingTime(), setRemainingTime()
191
*/
192
QDeadlineTimer::QDeadlineTimer(qint64 msecs, Qt::TimerType type)
noexcept
193
{
194
setRemainingTime(msecs, type);
195
}
196
197
/*!
198
\fn template <class Clock, class Duration> QDeadlineTimer::QDeadlineTimer(std::chrono::time_point<Clock, Duration> deadline, Qt::TimerType type)
199
200
Constructs a QDeadlineTimer object with a deadline at \a deadline time
201
point, converting from the clock source \c{Clock} to Qt's internal clock
202
source (see QElapsedTimer::clockType()).
203
204
If \a deadline is in the past, this QDeadlineTimer object is set to
205
expired, whereas if \a deadline is equal to \c{Duration::max()}, then this
206
object is set to never expire.
207
208
The QDeadlineTimer object will be constructed with the specified timer \a type.
209
210
\sa hasExpired(), isForever(), remainingTime(), setDeadline()
211
*/
212
213
/*!
214
\fn template <class Rep, class Period> QDeadlineTimer::QDeadlineTimer(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type)
215
216
Constructs a QDeadlineTimer object with a remaining time of \a remaining.
217
If \a remaining is zero or negative, this QDeadlineTimer object will be
218
mark as expired, whereas if \a remaining is equal to \c{duration::max()},
219
the object will be set to never expire.
220
221
The QDeadlineTimer object will be constructed with the specified timer \a type.
222
223
This constructor can be used with \l{chrono_literals Symbol Index}
224
{C++14's user-defined literals for time}, such as in:
225
226
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 3
227
228
For optimization purposes, if \a remaining is zero or negative, this
229
function may skip obtaining the current time and may instead use a value
230
known to be in the past. If that happens, deadline() may return an
231
unexpected value and this object cannot be used in calculation of how long
232
it is overdue. If that functionality is required, use
233
QDeadlineTimer::current() and add time to it.
234
235
\sa hasExpired(), isForever(), remainingTime(), setRemainingTime()
236
*/
237
238
/*!
239
\fn template <class Clock, class Duration> void QDeadlineTimer::setDeadline(std::chrono::time_point<Clock, Duration> deadline, Qt::TimerType type)
240
241
Sets this QDeadlineTimer to the deadline marked by \a deadline time
242
point, converting from the clock source \c{Clock} to Qt's internal clock
243
source (see QElapsedTimer::clockType()).
244
245
If \a deadline is in the past, this QDeadlineTimer object is set to
246
expired, whereas if \a deadline is equal to \c{Duration::max()}, then this
247
object is set to never expire.
248
249
The timer type for this QDeadlineTimer object will be set to the specified \a type.
250
251
\sa hasExpired(), isForever(), remainingTime(),
252
*/
253
254
/*!
255
Sets the remaining time for this QDeadlineTimer object to \a msecs
256
milliseconds from now, if \a msecs has a positive value. If \a msecs is
257
zero, this QDeadlineTimer object will be marked as expired, whereas a
258
negative value will set it to never expire.
259
260
For optimization purposes, if \a msecs is zero, this function may skip
261
obtaining the current time and may instead use a value known to be in the
262
past. If that happens, deadline() may return an unexpected value and this
263
object cannot be used in calculation of how long it is overdue. If that
264
functionality is required, use QDeadlineTimer::current() and add time to
265
it.
266
267
The timer type for this QDeadlineTimer object will be set to the specified \a timerType.
268
269
\note Prior to Qt 6.6, the only value that caused the timer to never expire
270
was -1.
271
272
\sa setPreciseRemainingTime(), hasExpired(), isForever(), remainingTime()
273
*/
274
void
QDeadlineTimer::setRemainingTime(qint64 msecs, Qt::TimerType timerType)
noexcept
275
{
276
if
(msecs < 0) {
277
*
this
= QDeadlineTimer(Forever, timerType);
278
}
else
if
(msecs == 0) {
279
*
this
= QDeadlineTimer(timerType);
280
t1 = std::numeric_limits<qint64>::min();
281
}
else
{
282
*
this
= current(timerType);
283
milliseconds ms(msecs);
284
t1 = add_saturate(t1, ms);
285
}
286
}
287
288
/*!
289
Sets the remaining time for this QDeadlineTimer object to \a secs seconds
290
plus \a nsecs nanoseconds from now, if \a secs has a positive value. If \a
291
secs is negative, this QDeadlineTimer will be set it to never expire (this
292
behavior does not apply to \a nsecs). If both parameters are zero, this
293
QDeadlineTimer will be marked as expired.
294
295
For optimization purposes, if both \a secs and \a nsecs are zero, this
296
function may skip obtaining the current time and may instead use a value
297
known to be in the past. If that happens, deadline() may return an
298
unexpected value and this object cannot be used in calculation of how long
299
it is overdue. If that functionality is required, use
300
QDeadlineTimer::current() and add time to it.
301
302
The timer type for this QDeadlineTimer object will be set to the specified
303
\a timerType.
304
305
\note Prior to Qt 6.6, the only condition that caused the timer to never
306
expire was when \a secs was -1.
307
308
\sa setRemainingTime(), hasExpired(), isForever(), remainingTime()
309
*/
310
void
QDeadlineTimer::setPreciseRemainingTime(qint64 secs, qint64 nsecs, Qt::TimerType timerType)
noexcept
311
{
312
if
(secs < 0) {
313
*
this
= QDeadlineTimer(Forever, timerType);
314
}
else
if
(secs == 0 && nsecs == 0) {
315
*
this
= QDeadlineTimer(timerType);
316
t1 = std::numeric_limits<qint64>::min();
317
}
else
{
318
*
this
= current(timerType);
319
t1 = add_saturate(t1, seconds{secs}, nanoseconds{nsecs});
320
}
321
}
322
323
/*!
324
\overload
325
\fn template <class Rep, class Period> void QDeadlineTimer::setRemainingTime(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type)
326
327
Sets the remaining time for this QDeadlineTimer object to \a remaining. If
328
\a remaining is zero or negative, this QDeadlineTimer object will be mark
329
as expired, whereas if \a remaining is equal to \c{duration::max()}, the
330
object will be set to never expire.
331
332
The timer type for this QDeadlineTimer object will be set to the specified \a type.
333
334
This function can be used with \l{chrono_literals Symbol Index}
335
{C++14's user-defined literals for time}, such as in:
336
337
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 4
338
339
\sa setDeadline(), remainingTime(), hasExpired(), isForever()
340
*/
341
342
/*!
343
\fn bool QDeadlineTimer::isForever() const
344
345
Returns true if this QDeadlineTimer object never expires, false otherwise.
346
For timers that never expire, remainingTime() always returns -1 and
347
deadline() returns the maximum value.
348
349
\sa ForeverConstant, hasExpired(), remainingTime()
350
*/
351
352
/*!
353
Returns true if this QDeadlineTimer object has expired, false if there
354
remains time left. For objects that have expired, remainingTime() will
355
return zero and deadline() will return a time point in the past.
356
357
QDeadlineTimer objects created with the \l {ForeverConstant} never expire
358
and this function always returns false for them.
359
360
\sa isForever(), remainingTime()
361
*/
362
bool
QDeadlineTimer::hasExpired()
const
noexcept
363
{
364
if
(isForever())
365
return
false
;
366
if
(t1 == std::numeric_limits<qint64>::min())
367
return
true
;
368
return
*
this
<= current(timerType());
369
}
370
371
/*!
372
\fn Qt::TimerType QDeadlineTimer::timerType() const
373
374
Returns the timer type is active for this object.
375
376
\sa setTimerType()
377
*/
378
379
/*!
380
Changes the timer type for this object to \a timerType.
381
382
The behavior for each possible value of \a timerType is operating-system
383
dependent. Qt::PreciseTimer will use the most precise timer that Qt can
384
find, with resolution of 1 millisecond or better, whereas QDeadlineTimer
385
will try to use a more coarse timer for Qt::CoarseTimer and
386
Qt::VeryCoarseTimer.
387
388
\sa Qt::TimerType
389
*/
390
void
QDeadlineTimer::setTimerType(Qt::TimerType timerType)
391
{
392
type = timerType;
393
}
394
395
/*!
396
Returns the remaining time in this QDeadlineTimer object in milliseconds.
397
If the timer has already expired, this function will return zero and it is
398
not possible to obtain the amount of time overdue with this function (to do
399
that, see deadline()). If the timer was set to never expire, this function
400
returns -1.
401
402
This function is suitable for use in Qt APIs that take a millisecond
403
timeout, such as the many \l QIODevice \c waitFor functions or the timed
404
lock functions in \l QMutex, \l QWaitCondition, \l QSemaphore, or
405
\l QReadWriteLock. For example:
406
407
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 5
408
409
\sa remainingTimeNSecs(), isForever(), hasExpired()
410
*/
411
qint64 QDeadlineTimer::remainingTime()
const
noexcept
412
{
413
if
(isForever())
414
return
-1;
415
416
nanoseconds nsecs(remainingTimeNSecs());
417
return
ceil<milliseconds>(nsecs).count();
418
}
419
420
/*!
421
Returns the remaining time in this QDeadlineTimer object in nanoseconds. If
422
the timer has already expired, this function will return zero and it is not
423
possible to obtain the amount of time overdue with this function. If the
424
timer was set to never expire, this function returns -1.
425
426
\sa remainingTime(), isForever(), hasExpired()
427
*/
428
qint64 QDeadlineTimer::remainingTimeNSecs()
const
noexcept
429
{
430
if
(isForever())
431
return
-1;
432
qint64 raw = rawRemainingTimeNSecs();
433
return
raw < 0 ? 0 : raw;
434
}
435
436
/*!
437
\internal
438
Same as remainingTimeNSecs, but may return negative remaining times. Does
439
not deal with Forever. In case of underflow, which is only possible if the
440
timer has expired, an arbitrary negative value is returned.
441
*/
442
qint64 QDeadlineTimer::rawRemainingTimeNSecs()
const
noexcept
443
{
444
if
(t1 == std::numeric_limits<qint64>::min())
445
return
t1;
// we'd saturate to this anyway
446
447
QDeadlineTimer now = current(timerType());
448
qint64 r;
449
if
(qSubOverflow(t1, now.t1, &r))
450
return
-1;
// any negative number is fine
451
return
r;
452
}
453
454
/*!
455
Returns the absolute time point for the deadline stored in QDeadlineTimer
456
object, calculated in milliseconds relative to the reference clock, the
457
same as QElapsedTimer::msecsSinceReference(). The value will be in the past
458
if this QDeadlineTimer has expired.
459
460
If this QDeadlineTimer never expires, this function returns
461
\c{std::numeric_limits<qint64>::max()}.
462
463
This function can be used to calculate the amount of time a timer is
464
overdue, by subtracting QDeadlineTimer::current() or
465
QElapsedTimer::msecsSinceReference(), as in the following example:
466
467
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 6
468
469
\note Timers that were created as expired have an indetermine time point in
470
the past as their deadline, so the above calculation may not work.
471
472
\sa remainingTime(), deadlineNSecs(), setDeadline()
473
*/
474
qint64 QDeadlineTimer::deadline()
const
noexcept
475
{
476
if
(isForever())
477
return
TimeReference::Max;
478
if
(t1 == TimeReference::Min)
479
return
t1;
480
481
nanoseconds ns(t1);
482
return
duration_cast<milliseconds>(ns).count();
483
}
484
485
/*!
486
Returns the absolute time point for the deadline stored in QDeadlineTimer
487
object, calculated in nanoseconds relative to the reference clock, the
488
same as QElapsedTimer::msecsSinceReference(). The value will be in the past
489
if this QDeadlineTimer has expired.
490
491
If this QDeadlineTimer never expires or the number of nanoseconds until the
492
deadline can't be accommodated in the return type, this function returns
493
\c{std::numeric_limits<qint64>::max()}.
494
495
This function can be used to calculate the amount of time a timer is
496
overdue, by subtracting QDeadlineTimer::current(), as in the following
497
example:
498
499
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 7
500
501
\note Timers that were created as expired have an indetermine time point in
502
the past as their deadline, so the above calculation may not work.
503
504
\sa remainingTime(), deadline(), setDeadline()
505
*/
506
qint64 QDeadlineTimer::deadlineNSecs()
const
noexcept
507
{
508
if
(isForever())
509
return
TimeReference::Max;
510
511
return
t1;
512
}
513
514
/*!
515
Sets the deadline for this QDeadlineTimer object to be the \a msecs
516
absolute time point, counted in milliseconds since the reference clock (the
517
same as QElapsedTimer::msecsSinceReference()), and the timer type to \a
518
timerType. If the value is in the past, this QDeadlineTimer will be marked
519
as expired.
520
521
If \a msecs is \c{std::numeric_limits<qint64>::max()} or the deadline is
522
beyond a representable point in the future, this QDeadlineTimer will be set
523
to never expire.
524
525
\sa setPreciseDeadline(), deadline(), deadlineNSecs(), setRemainingTime()
526
*/
527
void
QDeadlineTimer::setDeadline(qint64 msecs, Qt::TimerType timerType)
noexcept
528
{
529
if
(msecs == TimeReference::Max) {
530
*
this
= QDeadlineTimer(Forever, timerType);
531
return
;
532
}
533
534
type = timerType;
535
t1 = add_saturate(0, milliseconds{msecs});
536
}
537
538
/*!
539
Sets the deadline for this QDeadlineTimer object to be \a secs seconds and
540
\a nsecs nanoseconds since the reference clock epoch (the same as
541
QElapsedTimer::msecsSinceReference()), and the timer type to \a timerType.
542
If the value is in the past, this QDeadlineTimer will be marked as expired.
543
544
If \a secs or \a nsecs is \c{std::numeric_limits<qint64>::max()}, this
545
QDeadlineTimer will be set to never expire. If \a nsecs is more than 1
546
billion nanoseconds (1 second), then \a secs will be adjusted accordingly.
547
548
\sa setDeadline(), deadline(), deadlineNSecs(), setRemainingTime()
549
*/
550
void
QDeadlineTimer::setPreciseDeadline(qint64 secs, qint64 nsecs, Qt::TimerType timerType)
noexcept
551
{
552
type = timerType;
553
t1 = add_saturate(0, seconds{secs}, nanoseconds{nsecs});
554
}
555
556
/*!
557
Returns a QDeadlineTimer object whose deadline is extended from \a dt's
558
deadline by \a nsecs nanoseconds. If \a dt was set to never expire, this
559
function returns a QDeadlineTimer that will not expire either.
560
561
\note if \a dt was created as expired, its deadline is indeterminate and
562
adding an amount of time may or may not cause it to become unexpired.
563
*/
564
QDeadlineTimer QDeadlineTimer::addNSecs(QDeadlineTimer dt, qint64 nsecs)
noexcept
565
{
566
if
(dt.isForever())
567
return
dt;
568
569
dt.t1 = add_saturate(dt.t1, nanoseconds{nsecs});
570
return
dt;
571
}
572
573
/*!
574
\fn QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType)
575
576
Returns a QDeadlineTimer that is expired but is guaranteed to contain the
577
current time. Objects created by this function can participate in the
578
calculation of how long a timer is overdue, using the deadline() function.
579
580
The QDeadlineTimer object will be constructed with the specified \a timerType.
581
*/
582
QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType)
noexcept
583
{
584
// ensure we get nanoseconds; this will work so long as steady_clock's
585
// time_point isn't of finer resolution (picoseconds)
586
std::chrono::nanoseconds ns = std::chrono::steady_clock::now().time_since_epoch();
587
588
QDeadlineTimer result;
589
result.t1 = ns.count();
590
result.type = timerType;
591
return
result;
592
}
593
594
/*!
595
\fn bool QDeadlineTimer::operator==(const QDeadlineTimer &lhs, const QDeadlineTimer &rhs)
596
597
Returns true if the deadline on \a lhs and the deadline in \a rhs are the
598
same, false otherwise. The timer type used to create the two deadlines is
599
ignored. This function is equivalent to:
600
601
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 8
602
603
\note comparing QDeadlineTimer objects with different timer types is
604
not supported and may result in unpredictable behavior.
605
*/
606
607
/*!
608
\fn bool QDeadlineTimer::operator!=(const QDeadlineTimer &lhs, const QDeadlineTimer &rhs)
609
610
Returns true if the deadline on \a lhs and the deadline in \a rhs are
611
different, false otherwise. The timer type used to create the two deadlines
612
is ignored. This function is equivalent to:
613
614
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 9
615
616
\note comparing QDeadlineTimer objects with different timer types is
617
not supported and may result in unpredictable behavior.
618
*/
619
620
/*!
621
\fn bool QDeadlineTimer::operator<(const QDeadlineTimer &lhs, const QDeadlineTimer &rhs)
622
623
Returns true if the deadline on \a lhs is earlier than the deadline in \a
624
rhs, false otherwise. The timer type used to create the two deadlines is
625
ignored. This function is equivalent to:
626
627
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 10
628
629
\note comparing QDeadlineTimer objects with different timer types is
630
not supported and may result in unpredictable behavior.
631
*/
632
633
/*!
634
\fn bool QDeadlineTimer::operator<=(const QDeadlineTimer &lhs, const QDeadlineTimer &rhs)
635
636
Returns true if the deadline on \a lhs is earlier than or the same as the
637
deadline in \a rhs, false otherwise. The timer type used to create the two
638
deadlines is ignored. This function is equivalent to:
639
640
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 11
641
642
\note comparing QDeadlineTimer objects with different timer types is
643
not supported and may result in unpredictable behavior.
644
*/
645
646
/*!
647
\fn bool QDeadlineTimer::operator>(const QDeadlineTimer &lhs, const QDeadlineTimer &rhs)
648
649
Returns true if the deadline on \a lhs is later than the deadline in \a
650
rhs, false otherwise. The timer type used to create the two deadlines is
651
ignored. This function is equivalent to:
652
653
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 12
654
655
\note comparing QDeadlineTimer objects with different timer types is
656
not supported and may result in unpredictable behavior.
657
*/
658
659
/*!
660
\fn bool QDeadlineTimer::operator>=(const QDeadlineTimer &lhs, const QDeadlineTimer &rhs)
661
662
Returns true if the deadline on \a lhs is later than or the same as the
663
deadline in \a rhs, false otherwise. The timer type used to create the two
664
deadlines is ignored. This function is equivalent to:
665
666
\snippet code/src_corelib_kernel_qdeadlinetimer.cpp 13
667
668
\note comparing QDeadlineTimer objects with different timer types is
669
not supported and may result in unpredictable behavior.
670
*/
671
672
/*!
673
\fn QDeadlineTimer QDeadlineTimer::operator+(QDeadlineTimer dt, qint64 msecs)
674
675
Returns a QDeadlineTimer object whose deadline is \a msecs later than the
676
deadline stored in \a dt. If \a dt is set to never expire, this function
677
returns a QDeadlineTimer that does not expire either.
678
679
To add times of precision greater than 1 millisecond, use addNSecs().
680
*/
681
682
QDeadlineTimer
operator
+(QDeadlineTimer dt, qint64 msecs)
683
{
684
if
(dt.isForever())
685
return
dt;
686
687
dt.t1 = add_saturate(dt.t1, milliseconds{msecs});
688
return
dt;
689
}
690
691
/*!
692
\fn QDeadlineTimer QDeadlineTimer::operator+(qint64 msecs, QDeadlineTimer dt)
693
694
Returns a QDeadlineTimer object whose deadline is \a msecs later than the
695
deadline stored in \a dt. If \a dt is set to never expire, this function
696
returns a QDeadlineTimer that does not expire either.
697
698
To add times of precision greater than 1 millisecond, use addNSecs().
699
*/
700
701
/*!
702
\fn QDeadlineTimer QDeadlineTimer::operator-(QDeadlineTimer dt, qint64 msecs)
703
704
Returns a QDeadlineTimer object whose deadline is \a msecs before the
705
deadline stored in \a dt. If \a dt is set to never expire, this function
706
returns a QDeadlineTimer that does not expire either.
707
708
To subtract times of precision greater than 1 millisecond, use addNSecs().
709
*/
710
711
/*!
712
\fn QDeadlineTimer &QDeadlineTimer::operator+=(qint64 msecs)
713
714
Extends this QDeadlineTimer object by \a msecs milliseconds and returns
715
itself. If this object is set to never expire, this function does nothing.
716
717
To add times of precision greater than 1 millisecond, use addNSecs().
718
*/
719
720
/*!
721
\fn QDeadlineTimer &QDeadlineTimer::operator-=(qint64 msecs)
722
723
Shortens this QDeadlineTimer object by \a msecs milliseconds and returns
724
itself. If this object is set to never expire, this function does nothing.
725
726
To subtract times of precision greater than 1 millisecond, use addNSecs().
727
*/
728
729
/*!
730
\fn void QDeadlineTimer::swap(QDeadlineTimer &other)
731
\memberswap{deadline timer}
732
*/
733
734
/*!
735
\fn template <class Clock, class Duration> QDeadlineTimer & QDeadlineTimer::operator=(std::chrono::time_point<Clock, Duration> deadline_)
736
737
Assigns \a deadline_ to this deadline timer.
738
*/
739
740
/*!
741
\fn template <class Rep, class Period> QDeadlineTimer & QDeadlineTimer::operator=(std::chrono::duration<Rep, Period> remaining)
742
743
Sets this deadline timer to the \a remaining time.
744
*/
745
746
/*!
747
\fn std::chrono::nanoseconds QDeadlineTimer::remainingTimeAsDuration() const
748
749
Returns the time remaining before the deadline.
750
*/
751
752
QT_END_NAMESPACE
operator+
QDeadlineTimer operator+(QDeadlineTimer dt, qint64 msecs)
Definition
qdeadlinetimer.cpp:682
add_saturate
static qint64 add_saturate(qint64 t1, Duration1 dur, Durations... extra)
Definition
qdeadlinetimer.cpp:23
qtbase
src
corelib
kernel
qdeadlinetimer.cpp
Generated on
for Qt by
1.18.0