Make QElapsedTimer default to invalid (and now non-POD).
The practical uses of a POD QElapsedTimer are not really that clear, and the number of misuses of this API are quite high. Default the state to invalid to prevent against mistakes. [ChangeLog][QtCore][QElapsedTimer] Is no longer a POD. Change-Id: I267292acf2bfca7404e3e449dd04410441d7ce26 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
8d0e6000cb
commit
3006bd2d44
@ -201,6 +201,17 @@ QT_BEGIN_NAMESPACE
|
||||
\sa clockType(), isMonotonic()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QElapsedTimer::QElapsedTimer()
|
||||
\since 5.4
|
||||
|
||||
Constructs an invalid QElapsedTimer. A timer becomes valid once it has been
|
||||
started.
|
||||
|
||||
\sa isValid(), start()
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool QElapsedTimer::operator ==(const QElapsedTimer &other) const
|
||||
|
||||
@ -230,8 +241,8 @@ void QElapsedTimer::invalidate() Q_DECL_NOTHROW
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c false if this object was invalidated by a call to invalidate() and
|
||||
has not been restarted since.
|
||||
Returns \c false if the timer has never been started or invalidated by a
|
||||
call to invalidate().
|
||||
|
||||
\sa invalidate(), start(), restart()
|
||||
*/
|
||||
|
@ -57,6 +57,13 @@ public:
|
||||
MachAbsoluteTime,
|
||||
PerformanceCounter
|
||||
};
|
||||
|
||||
Q_DECL_CONSTEXPR QElapsedTimer()
|
||||
: t1(Q_INT64_C(0x8000000000000000))
|
||||
, t2(Q_INT64_C(0x8000000000000000))
|
||||
{
|
||||
}
|
||||
|
||||
static ClockType clockType() Q_DECL_NOTHROW;
|
||||
static bool isMonotonic() Q_DECL_NOTHROW;
|
||||
|
||||
|
@ -87,6 +87,8 @@ void QElapsedTimer::start() Q_DECL_NOTHROW
|
||||
and then starting the timer again with start(), but it does so in one
|
||||
single operation, avoiding the need to obtain the clock value twice.
|
||||
|
||||
Restarting the timer makes it valid again.
|
||||
|
||||
The following example illustrates how to use this function to calibrate a
|
||||
parameter to a slow operation (for example, an iteration count) so that
|
||||
this operation takes at least 250 milliseconds:
|
||||
|
@ -48,12 +48,7 @@ static const int minResolution = 50; // the minimum resolution for the tests
|
||||
|
||||
QDebug operator<<(QDebug s, const QElapsedTimer &t)
|
||||
{
|
||||
union {
|
||||
QElapsedTimer t;
|
||||
struct { qint64 t1, t2; } i;
|
||||
} copy;
|
||||
copy.t = t;
|
||||
s.nospace() << "(" << copy.i.t1 << ", " << copy.i.t2 << ")";
|
||||
s.nospace() << "(" << t.msecsSinceReference() << ")";
|
||||
return s.space();
|
||||
}
|
||||
|
||||
@ -81,8 +76,7 @@ void tst_QElapsedTimer::validity()
|
||||
{
|
||||
QElapsedTimer t;
|
||||
|
||||
t.invalidate();
|
||||
QVERIFY(!t.isValid());
|
||||
QVERIFY(!t.isValid()); // non-POD now, it should always start invalid
|
||||
|
||||
t.start();
|
||||
QVERIFY(t.isValid());
|
||||
|
Loading…
Reference in New Issue
Block a user