![]() This means two processes' reckoning of the time since the reference may be different by multiples of 2^32 milliseconds. On Windows systems, the clock overflows after 2^32 milliseconds, which corresponds to roughly 49.7 days. Windows Vista and Windows Server 2008 support the extended 64-bit tick counter, which allows avoiding the overflow. The TickCounter clock type is the only clock type that may overflow. If the high-precision performance counter is available on Windows, the PerformanceCounter clock type is used instead. This clock type is used on Windows platforms. The tick counter clock type is based on the system's or the processor's tick counter, multiplied by the duration of a tick. This clock type is used on Unix systems which support POSIX monotonic clocks ( _POSIX_MONOTONIC_CLOCK). This is the system's monotonic clock, expressed in milliseconds since an arbitrary point in the past. This is the only non-monotonic clock that QElapsedTimer may use. ![]() This clock type is currently only used on Unix systems that do not support monotonic clocks (see below). It's equivalent to the value returned by the C and POSIX time function, with the milliseconds added. The system time clock is purely the real time, expressed in milliseconds since at 0:00 UTC. This clock is monotonic and does not overflow. The high-resolution performance counter provided by Windows. The Mach kernel's absolute time ( macOS and iOS). The system's tick counter, used on Windows systems. The system's monotonic clock, usually found in Unix systems. The information on which clocks types may overflow and how to remedy that issue is documented along with the clock types. However, when extracting the time since reference from QElapsedTimer, two different processes in the same machine may have different understanding of how much time has actually elapsed. QElapsedTimer deals with this overflow issue and presents a consistent timing. Some of the clocks used by QElapsedTimer have a limited range and may overflow after hitting the upper limit (usually 32-bit). If comparing to values produced by other APIs, you should check that the clock used is the same as QElapsedTimer (see QElapsedTimer::clockType()). QElapsedTimer will always use the same clock, so it's safe to compare with the value coming from another process in the same machine. It is, however, possible to exchange the value with other processes running on the same machine, provided that they also use the same reference clock. These values should never be exchanged across the network or saved to disk, since there's no telling whether the computer node receiving the data is the same as the one originating it or if it has rebooted since. This is especially true if the time since the reference is extracted from the QElapsedTimer object ( QElapsedTimer::msecsSinceReference()) and serialised. On the other hand, this means QElapsedTimer values can only be compared with other values that use the same reference. Also unlike QTime, QElapsedTimer is immune to changes in the timezone settings, such as daylight-saving periods. This has the added benefit that QElapsedTimer is immune to time adjustments, such as the user correcting the time. QElapsedTimer will use the platform's monotonic reference clock in all platforms that support it (see QElapsedTimer::isMonotonic()). 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) The simplest example of such a case is for debugging purposes, as in the following example: QElapsedTimer timer Īnother use-case is to execute a certain operation for a specific timeslice. The typical use-case for the class is to determine how much time was spent in a slow operation. This means it's not possible to convert QElapsedTimer objects to a human-readable time. However, unlike QTime, QElapsedTimer tries to use monotonic clocks if possible. ![]() ![]() Its API is similar to that of QTime, so code that was using that can be ported quickly to the new class. The QElapsedTimer class is usually used to quickly calculate how much time has elapsed between two events. The QElapsedTimer class provides a fast way to calculate elapsed times.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |