[][src]Struct qt_core::QElapsedTimer

#[repr(C)]pub struct QElapsedTimer { /* fields omitted */ }

The QElapsedTimer class provides a fast way to calculate elapsed times.

C++ class: QElapsedTimer.

C++ documentation:

The QElapsedTimer class provides a fast way to calculate elapsed times.

The QElapsedTimer class is usually used to quickly calculate how much time has elapsed between two events. Its API is similar to that of QTime, so code that was using that can be ported quickly to the new class.

However, unlike QTime, QElapsedTimer tries to use monotonic clocks if possible. This means it's not possible to convert QElapsedTimer objects to a human-readable time.

The typical use-case for the class is to determine how much time was spent in a slow operation. The simplest example of such a case is for debugging purposes, as in the following example:

QElapsedTimer timer; timer.start();

slowOperation1();

qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";

In this example, the timer is started by a call to start() and the elapsed timer is calculated by the elapsed() function.

The time elapsed can also be used to recalculate the time available for another operation, after the first one is complete. This is useful when the execution must complete within a certain time period, but several steps are needed. The waitFor-type functions in QIODevice and its subclasses are good examples of such need. In that case, the code could be as follows:

void executeSlowOperations(int timeout) { QElapsedTimer timer; timer.start(); slowOperation1();

int remainingTime = timeout - timer.elapsed(); if (remainingTime > 0) slowOperation2(remainingTime); }

Another use-case is to execute a certain operation for a specific timeslice. For this, QElapsedTimer provides the hasExpired() convenience function, which can be used to determine if a certain number of milliseconds has already elapsed:

void executeOperationsForTime(int ms) { QElapsedTimer timer; timer.start();

while (!timer.hasExpired(ms)) slowOperation1(); }

It is often more convenient to use QDeadlineTimer in this case, which counts towards a timeout in the future instead of tracking elapsed time.

Methods

impl QElapsedTimer[src]

pub unsafe fn clock_type() -> ClockType[src]

Returns the clock type that this QElapsedTimer implementation uses.

Calls C++ function: static QElapsedTimer::ClockType QElapsedTimer::clockType().

C++ documentation:

Returns the clock type that this QElapsedTimer implementation uses.

See also isMonotonic().

pub unsafe fn copy_from(
    &self,
    other: impl CastInto<Ref<QElapsedTimer>>
) -> Ref<QElapsedTimer>
[src]

The QElapsedTimer class provides a fast way to calculate elapsed times.

Calls C++ function: QElapsedTimer& QElapsedTimer::operator=(const QElapsedTimer& other).

C++ documentation:

The QElapsedTimer class provides a fast way to calculate elapsed times.

The QElapsedTimer class is usually used to quickly calculate how much time has elapsed between two events. Its API is similar to that of QTime, so code that was using that can be ported quickly to the new class.

However, unlike QTime, QElapsedTimer tries to use monotonic clocks if possible. This means it's not possible to convert QElapsedTimer objects to a human-readable time.

The typical use-case for the class is to determine how much time was spent in a slow operation. The simplest example of such a case is for debugging purposes, as in the following example:

QElapsedTimer timer; timer.start();

slowOperation1();

qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";

In this example, the timer is started by a call to start() and the elapsed timer is calculated by the elapsed() function.

The time elapsed can also be used to recalculate the time available for another operation, after the first one is complete. This is useful when the execution must complete within a certain time period, but several steps are needed. The waitFor-type functions in QIODevice and its subclasses are good examples of such need. In that case, the code could be as follows:

void executeSlowOperations(int timeout) { QElapsedTimer timer; timer.start(); slowOperation1();

int remainingTime = timeout - timer.elapsed(); if (remainingTime > 0) slowOperation2(remainingTime); }

Another use-case is to execute a certain operation for a specific timeslice. For this, QElapsedTimer provides the hasExpired() convenience function, which can be used to determine if a certain number of milliseconds has already elapsed:

void executeOperationsForTime(int ms) { QElapsedTimer timer; timer.start();

while (!timer.hasExpired(ms)) slowOperation1(); }

It is often more convenient to use QDeadlineTimer in this case, which counts towards a timeout in the future instead of tracking elapsed time.

pub unsafe fn elapsed(&self) -> i64[src]

Returns the number of milliseconds since this QElapsedTimer was last started.

Calls C++ function: qint64 QElapsedTimer::elapsed() const.

C++ documentation:

Returns the number of milliseconds since this QElapsedTimer was last started.

Calling this function on a QElapsedTimer that is invalid results in undefined behavior.

See also start(), restart(), hasExpired(), isValid(), and invalidate().

pub unsafe fn has_expired(&self, timeout: i64) -> bool[src]

Returns true if this QElapsedTimer has already expired by timeout milliseconds (that is, more than timeout milliseconds have elapsed). The value of timeout can be -1 to indicate that this timer does not expire, in which case this function will always return false.

Calls C++ function: bool QElapsedTimer::hasExpired(qint64 timeout) const.

C++ documentation:

Returns true if this QElapsedTimer has already expired by timeout milliseconds (that is, more than timeout milliseconds have elapsed). The value of timeout can be -1 to indicate that this timer does not expire, in which case this function will always return false.

See also elapsed() and QDeadlineTimer.

pub unsafe fn invalidate(&self)[src]

Marks this QElapsedTimer object as invalid.

Calls C++ function: void QElapsedTimer::invalidate().

C++ documentation:

Marks this QElapsedTimer object as invalid.

An invalid object can be checked with isValid(). Calculations of timer elapsed since invalid data are undefined and will likely produce bizarre results.

See also isValid(), start(), and restart().

pub unsafe fn is_monotonic() -> bool[src]

Returns true if this is a monotonic clock, false otherwise. See the information on the different clock types to understand which ones are monotonic.

Calls C++ function: static bool QElapsedTimer::isMonotonic().

C++ documentation:

Returns true if this is a monotonic clock, false otherwise. See the information on the different clock types to understand which ones are monotonic.

See also clockType() and QElapsedTimer::ClockType.

pub unsafe fn is_valid(&self) -> bool[src]

Returns false if the timer has never been started or invalidated by a call to invalidate().

Calls C++ function: bool QElapsedTimer::isValid() const.

C++ documentation:

Returns false if the timer has never been started or invalidated by a call to invalidate().

See also invalidate(), start(), and restart().

pub unsafe fn msecs_since_reference(&self) -> i64[src]

Returns the number of milliseconds between last time this QElapsedTimer object was started and its reference clock's start.

Calls C++ function: qint64 QElapsedTimer::msecsSinceReference() const.

C++ documentation:

Returns the number of milliseconds between last time this QElapsedTimer object was started and its reference clock's start.

This number is usually arbitrary for all clocks except the QElapsedTimer::SystemTime clock. For that clock type, this number is the number of milliseconds since January 1st, 1970 at 0:00 UTC (that is, it is the Unix time expressed in milliseconds).

On Linux, Windows and Apple platforms, this value is usually the time since the system boot, though it usually does not include the time the system has spent in sleep states.

See also clockType() and elapsed().

pub unsafe fn msecs_to(&self, other: impl CastInto<Ref<QElapsedTimer>>) -> i64[src]

Returns the number of milliseconds between this QElapsedTimer and other. If other was started before this object, the returned value will be negative. If it was started later, the returned value will be positive.

Calls C++ function: qint64 QElapsedTimer::msecsTo(const QElapsedTimer& other) const.

C++ documentation:

Returns the number of milliseconds between this QElapsedTimer and other. If other was started before this object, the returned value will be negative. If it was started later, the returned value will be positive.

The return value is undefined if this object or other were invalidated.

See also secsTo() and elapsed().

pub unsafe fn new() -> CppBox<QElapsedTimer>[src]

Constructs an invalid QElapsedTimer. A timer becomes valid once it has been started.

Calls C++ function: [constructor] void QElapsedTimer::QElapsedTimer().

C++ documentation:

Constructs an invalid QElapsedTimer. A timer becomes valid once it has been started.

This function was introduced in Qt 5.4.

See also isValid() and start().

pub unsafe fn new_copy(
    other: impl CastInto<Ref<QElapsedTimer>>
) -> CppBox<QElapsedTimer>
[src]

The QElapsedTimer class provides a fast way to calculate elapsed times.

Calls C++ function: [constructor] void QElapsedTimer::QElapsedTimer(const QElapsedTimer& other).

C++ documentation:

The QElapsedTimer class provides a fast way to calculate elapsed times.

The QElapsedTimer class is usually used to quickly calculate how much time has elapsed between two events. Its API is similar to that of QTime, so code that was using that can be ported quickly to the new class.

However, unlike QTime, QElapsedTimer tries to use monotonic clocks if possible. This means it's not possible to convert QElapsedTimer objects to a human-readable time.

The typical use-case for the class is to determine how much time was spent in a slow operation. The simplest example of such a case is for debugging purposes, as in the following example:

QElapsedTimer timer; timer.start();

slowOperation1();

qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";

In this example, the timer is started by a call to start() and the elapsed timer is calculated by the elapsed() function.

The time elapsed can also be used to recalculate the time available for another operation, after the first one is complete. This is useful when the execution must complete within a certain time period, but several steps are needed. The waitFor-type functions in QIODevice and its subclasses are good examples of such need. In that case, the code could be as follows:

void executeSlowOperations(int timeout) { QElapsedTimer timer; timer.start(); slowOperation1();

int remainingTime = timeout - timer.elapsed(); if (remainingTime > 0) slowOperation2(remainingTime); }

Another use-case is to execute a certain operation for a specific timeslice. For this, QElapsedTimer provides the hasExpired() convenience function, which can be used to determine if a certain number of milliseconds has already elapsed:

void executeOperationsForTime(int ms) { QElapsedTimer timer; timer.start();

while (!timer.hasExpired(ms)) slowOperation1(); }

It is often more convenient to use QDeadlineTimer in this case, which counts towards a timeout in the future instead of tracking elapsed time.

pub unsafe fn nsecs_elapsed(&self) -> i64[src]

Returns the number of nanoseconds since this QElapsedTimer was last started.

Calls C++ function: qint64 QElapsedTimer::nsecsElapsed() const.

C++ documentation:

Returns the number of nanoseconds since this QElapsedTimer was last started.

Calling this function on a QElapsedTimer that is invalid results in undefined behavior.

On platforms that do not provide nanosecond resolution, the value returned will be the best estimate available.

This function was introduced in Qt 4.8.

See also start(), restart(), hasExpired(), and invalidate().

pub unsafe fn restart(&self) -> i64[src]

Restarts the timer and returns the time elapsed since the previous start. This function is equivalent to obtaining the elapsed time with elapsed() 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.

Calls C++ function: qint64 QElapsedTimer::restart().

C++ documentation:

Restarts the timer and returns the time elapsed since the previous start. This function is equivalent to obtaining the elapsed time with elapsed() 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.

Calling this function on a QElapsedTimer that is invalid results in undefined behavior.

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:

QElapsedTimer timer;

int count = 1; timer.start(); do { count *= 2; slowOperation2(count); } while (timer.restart() < 250);

return count;

See also start(), invalidate(), elapsed(), and isValid().

pub unsafe fn secs_to(&self, other: impl CastInto<Ref<QElapsedTimer>>) -> i64[src]

Returns the number of seconds between this QElapsedTimer and other. If other was started before this object, the returned value will be negative. If it was started later, the returned value will be positive.

Calls C++ function: qint64 QElapsedTimer::secsTo(const QElapsedTimer& other) const.

C++ documentation:

Returns the number of seconds between this QElapsedTimer and other. If other was started before this object, the returned value will be negative. If it was started later, the returned value will be positive.

Calling this function on or with a QElapsedTimer that is invalid results in undefined behavior.

See also msecsTo() and elapsed().

pub unsafe fn start(&self)[src]

Starts this timer. Once started, a timer value can be checked with elapsed() or msecsSinceReference().

Calls C++ function: void QElapsedTimer::start().

C++ documentation:

Starts this timer. Once started, a timer value can be checked with elapsed() or msecsSinceReference().

Normally, a timer is started just before a lengthy operation, such as:

QElapsedTimer timer; timer.start();

slowOperation1();

qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";

Also, starting a timer makes it valid again.

See also restart(), invalidate(), and elapsed().

Trait Implementations

impl CppDeletable for QElapsedTimer[src]

unsafe fn delete(&self)[src]

The QElapsedTimer class provides a fast way to calculate elapsed times.

Calls C++ function: [destructor] void QElapsedTimer::~QElapsedTimer().

C++ documentation:

The QElapsedTimer class provides a fast way to calculate elapsed times.

The QElapsedTimer class is usually used to quickly calculate how much time has elapsed between two events. Its API is similar to that of QTime, so code that was using that can be ported quickly to the new class.

However, unlike QTime, QElapsedTimer tries to use monotonic clocks if possible. This means it's not possible to convert QElapsedTimer objects to a human-readable time.

The typical use-case for the class is to determine how much time was spent in a slow operation. The simplest example of such a case is for debugging purposes, as in the following example:

QElapsedTimer timer; timer.start();

slowOperation1();

qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";

In this example, the timer is started by a call to start() and the elapsed timer is calculated by the elapsed() function.

The time elapsed can also be used to recalculate the time available for another operation, after the first one is complete. This is useful when the execution must complete within a certain time period, but several steps are needed. The waitFor-type functions in QIODevice and its subclasses are good examples of such need. In that case, the code could be as follows:

void executeSlowOperations(int timeout) { QElapsedTimer timer; timer.start(); slowOperation1();

int remainingTime = timeout - timer.elapsed(); if (remainingTime > 0) slowOperation2(remainingTime); }

Another use-case is to execute a certain operation for a specific timeslice. For this, QElapsedTimer provides the hasExpired() convenience function, which can be used to determine if a certain number of milliseconds has already elapsed:

void executeOperationsForTime(int ms) { QElapsedTimer timer; timer.start();

while (!timer.hasExpired(ms)) slowOperation1(); }

It is often more convenient to use QDeadlineTimer in this case, which counts towards a timeout in the future instead of tracking elapsed time.

impl PartialEq<Ref<QElapsedTimer>> for QElapsedTimer[src]

fn eq(&self, other: &Ref<QElapsedTimer>) -> bool[src]

Returns true if this object and other contain the same time.

Calls C++ function: bool QElapsedTimer::operator==(const QElapsedTimer& other) const.

C++ documentation:

Returns true if this object and other contain the same time.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.