Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 357

qtbase5-doc-5.9.4-1.1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qelapsedtimer.cpp -->
  <title>QElapsedTimer Class | Qt Core 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QElapsedTimer</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#reference-clocks">Reference Clocks</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QElapsedTimer Class</h1>
<!-- $$$QElapsedTimer-brief -->
<p>The <a href="qelapsedtimer.html">QElapsedTimer</a> class provides a fast way to calculate elapsed times. <a href="#details">More...</a></p>
<!-- @@@QElapsedTimer -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QElapsedTimer&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 4.7</td></tr></table></div><ul>
<li><a href="qelapsedtimer-members.html">List of all members, including inherited members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#ClockType-enum">ClockType</a></b> { SystemTime, MonotonicClock, TickCounter, MachAbsoluteTime, PerformanceCounter }</td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#elapsed">elapsed</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#hasExpired">hasExpired</a></b>(qint64 <i>timeout</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#invalidate">invalidate</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#isValid">isValid</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#msecsSinceReference">msecsSinceReference</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#msecsTo">msecsTo</a></b>(const QElapsedTimer &amp;<i>other</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#nsecsElapsed">nsecsElapsed</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#restart">restart</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#secsTo">secsTo</a></b>(const QElapsedTimer &amp;<i>other</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#start">start</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#operator-not-eq">operator!=</a></b>(const QElapsedTimer &amp;<i>other</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#operator-eq-eq">operator==</a></b>(const QElapsedTimer &amp;<i>other</i>) const</td></tr>
</table></div>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> ClockType </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#clockType">clockType</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qelapsedtimer.html#isMonotonic">isMonotonic</a></b>()</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QElapsedTimer-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qelapsedtimer.html">QElapsedTimer</a> class provides a fast way to calculate elapsed times.</p>
<p>The <a href="qelapsedtimer.html">QElapsedTimer</a> class is usually used to quickly calculate how much time has elapsed between two events. Its API is similar to that of <a href="qtime.html">QTime</a>, so code that was using that can be ported quickly to the new class.</p>
<p>However, unlike <a href="qtime.html">QTime</a>, <a href="qelapsedtimer.html">QElapsedTimer</a> tries to use monotonic clocks if possible. This means it's not possible to convert <a href="qelapsedtimer.html">QElapsedTimer</a> objects to a human-readable time.</p>
<p>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:</p>
<pre class="cpp">

      <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> timer;
      timer<span class="operator">.</span>start();

      slowOperation1();

      <a href="qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The slow operation took&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> timer<span class="operator">.</span>elapsed() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;milliseconds&quot;</span>;

</pre>
<p>In this example, the timer is started by a call to <a href="qelapsedtimer.html#start">start</a>() and the elapsed timer is calculated by the <a href="qelapsedtimer.html#elapsed">elapsed</a>() function.</p>
<p>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 <code>waitFor</code>-type functions in <a href="qiodevice.html">QIODevice</a> and its subclasses are good examples of such need. In that case, the code could be as follows:</p>
<pre class="cpp">

  <span class="type">void</span> executeSlowOperations(<span class="type">int</span> timeout)
  {
      <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> timer;
      timer<span class="operator">.</span>start();
      slowOperation1();

      <span class="type">int</span> remainingTime <span class="operator">=</span> timeout <span class="operator">-</span> timer<span class="operator">.</span>elapsed();
      <span class="keyword">if</span> (remainingTime <span class="operator">&gt;</span> <span class="number">0</span>)
          slowOperation2(remainingTime);
  }

</pre>
<p>Another use-case is to execute a certain operation for a specific timeslice. For this, <a href="qelapsedtimer.html">QElapsedTimer</a> provides the <a href="qelapsedtimer.html#hasExpired">hasExpired</a>() convenience function, which can be used to determine if a certain number of milliseconds has already elapsed:</p>
<pre class="cpp">

  <span class="type">void</span> executeOperationsForTime(<span class="type">int</span> ms)
  {
      <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> timer;
      timer<span class="operator">.</span>start();

      <span class="keyword">while</span> (<span class="operator">!</span>timer<span class="operator">.</span>hasExpired(ms))
          slowOperation1();
  }

</pre>
<p>It is often more convenient to use <a href="qdeadlinetimer.html">QDeadlineTimer</a> in this case, which counts towards a timeout in the future instead of tracking elapsed time.</p>
<a name="reference-clocks"></a>
<h3 >Reference Clocks</h3>
<p><a href="qelapsedtimer.html">QElapsedTimer</a> will use the platform's monotonic reference clock in all platforms that support it (see <a href="qelapsedtimer.html#isMonotonic">QElapsedTimer::isMonotonic</a>()). This has the added benefit that <a href="qelapsedtimer.html">QElapsedTimer</a> is immune to time adjustments, such as the user correcting the time. Also unlike <a href="qtime.html">QTime</a>, <a href="qelapsedtimer.html">QElapsedTimer</a> is immune to changes in the timezone settings, such as daylight-saving periods.</p>
<p>On the other hand, this means <a href="qelapsedtimer.html">QElapsedTimer</a> values can only be compared with other values that use the same reference. This is especially true if the time since the reference is extracted from the <a href="qelapsedtimer.html">QElapsedTimer</a> object (<a href="qelapsedtimer.html#msecsSinceReference">QElapsedTimer::msecsSinceReference</a>()) and serialised. 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.</p>
<p>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. <a href="qelapsedtimer.html">QElapsedTimer</a> will always use the same clock, so it's safe to compare with the value coming from another process in the same machine. If comparing to values produced by other APIs, you should check that the clock used is the same as <a href="qelapsedtimer.html">QElapsedTimer</a> (see <a href="qelapsedtimer.html#clockType">QElapsedTimer::clockType</a>()).</p>
<a name="32-bit-overflows"></a>
<h4 >32-bit overflows</h4>
<p>Some of the clocks used by <a href="qelapsedtimer.html">QElapsedTimer</a> have a limited range and may overflow after hitting the upper limit (usually 32-bit). <a href="qelapsedtimer.html">QElapsedTimer</a> deals with this overflow issue and presents a consistent timing. However, when extracting the time since reference from <a href="qelapsedtimer.html">QElapsedTimer</a>, two different processes in the same machine may have different understanding of how much time has actually elapsed.</p>
<p>The information on which clocks types may overflow and how to remedy that issue is documented along with the clock types.</p>
</div>
<p><b>See also </b><a href="qtime.html">QTime</a>, <a href="qtimer.html">QTimer</a>, and <a href="qdeadlinetimer.html">QDeadlineTimer</a>.</p>
<!-- @@@QElapsedTimer -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$ClockType$$$SystemTime$$$MonotonicClock$$$TickCounter$$$MachAbsoluteTime$$$PerformanceCounter -->
<h3 class="fn" id="ClockType-enum"><a name="ClockType-enum"></a>enum QElapsedTimer::<span class="name">ClockType</span></h3>
<p>This enum contains the different clock types that <a href="qelapsedtimer.html">QElapsedTimer</a> may use.</p>
<p><a href="qelapsedtimer.html">QElapsedTimer</a> will always use the same clock type in a particular machine, so this value will not change during the lifetime of a program. It is provided so that <a href="qelapsedtimer.html">QElapsedTimer</a> can be used with other non-Qt implementations, to guarantee that the same reference clock is being used.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QElapsedTimer::SystemTime</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">The human-readable system time. This clock is not monotonic.</td></tr>
<tr><td class="topAlign"><code>QElapsedTimer::MonotonicClock</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">The system's monotonic clock, usually found in Unix systems. This clock is monotonic and does not overflow.</td></tr>
<tr><td class="topAlign"><code>QElapsedTimer::TickCounter</code></td><td class="topAlign tblval"><code>2</code></td><td class="topAlign">The system's tick counter, used on Windows systems. This clock may overflow.</td></tr>
<tr><td class="topAlign"><code>QElapsedTimer::MachAbsoluteTime</code></td><td class="topAlign tblval"><code>3</code></td><td class="topAlign">The Mach kernel's absolute time (macOS and iOS). This clock is monotonic and does not overflow.</td></tr>
<tr><td class="topAlign"><code>QElapsedTimer::PerformanceCounter</code></td><td class="topAlign tblval"><code>4</code></td><td class="topAlign">The high-resolution performance counter provided by Windows. This clock is monotonic and does not overflow.</td></tr>
</table></div>
<a name="systemtime"></a>
<h5 >SystemTime</h5>
<p>The system time clock is purely the real time, expressed in milliseconds since Jan 1, 1970 at 0:00 UTC. It's equivalent to the value returned by the C and POSIX <code>time</code> function, with the milliseconds added. This clock type is currently only used on Unix systems that do not support monotonic clocks (see below).</p>
<p>This is the only non-monotonic clock that <a href="qelapsedtimer.html">QElapsedTimer</a> may use.</p>
<a name="monotonicclock"></a>
<h5 >MonotonicClock</h5>
<p>This is the system's monotonic clock, expressed in milliseconds since an arbitrary point in the past. This clock type is used on Unix systems which support POSIX monotonic clocks (<code>_POSIX_MONOTONIC_CLOCK</code>).</p>
<p>This clock does not overflow.</p>
<a name="tickcounter"></a>
<h5 >TickCounter</h5>
<p>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 Windows platforms. If the high-precision performance counter is available on Windows, the <code><a href="#performancecounter">PerformanceCounter</a></code> clock type is used instead.</p>
<p>The <a href="#tickcounter">TickCounter</a> clock type is the only clock type that may overflow. Windows Vista and Windows Server 2008 support the extended 64-bit tick counter, which allows avoiding the overflow.</p>
<p>On Windows systems, the clock overflows after 2^32 milliseconds, which corresponds to roughly 49.7 days. This means two processes' reckoning of the time since the reference may be different by multiples of 2^32 milliseconds. When comparing such values, it's recommended that the high 32 bits of the millisecond count be masked off.</p>
<a name="machabsolutetime"></a>
<h5 >MachAbsoluteTime</h5>
<p>This clock type is based on the absolute time presented by Mach kernels, such as that found on macOS. This clock type is presented separately from <a href="#monotonicclock">MonotonicClock</a> since macOS and iOS are also Unix systems and may support a POSIX monotonic clock with values differing from the Mach absolute time.</p>
<p>This clock is monotonic and does not overflow.</p>
<a name="performancecounter"></a>
<h5 >PerformanceCounter</h5>
<p>This clock uses the Windows functions <code>QueryPerformanceCounter</code> and <code>QueryPerformanceFrequency</code> to access the system's high-precision performance counter. Since this counter may not be available on all systems, <a href="qelapsedtimer.html">QElapsedTimer</a> will fall back to the <code><a href="#tickcounter">TickCounter</a></code> clock automatically, if this clock cannot be used.</p>
<p>This clock is monotonic and does not overflow.</p>
<p><b>See also </b><a href="qelapsedtimer.html#clockType">clockType</a>() and <a href="qelapsedtimer.html#isMonotonic">isMonotonic</a>().</p>
<!-- @@@ClockType -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QElapsedTimer[overload1]$$$QElapsedTimer -->
<h3 class="fn" id="QElapsedTimer"><a name="QElapsedTimer"></a>QElapsedTimer::<span class="name">QElapsedTimer</span>()</h3>
<p>Constructs an invalid <a href="qelapsedtimer.html">QElapsedTimer</a>. A timer becomes valid once it has been started.</p>
<p>This function was introduced in  Qt 5.4.</p>
<p><b>See also </b><a href="qelapsedtimer.html#isValid">isValid</a>() and <a href="qelapsedtimer.html#start">start</a>().</p>
<!-- @@@QElapsedTimer -->
<!-- $$$clockType[overload1]$$$clockType -->
<h3 class="fn" id="clockType"><a name="clockType"></a><code>[static] </code><span class="type"><a href="qelapsedtimer.html#ClockType-enum">ClockType</a></span> QElapsedTimer::<span class="name">clockType</span>()</h3>
<p>Returns the clock type that this <a href="qelapsedtimer.html">QElapsedTimer</a> implementation uses.</p>
<p><b>See also </b><a href="qelapsedtimer.html#isMonotonic">isMonotonic</a>().</p>
<!-- @@@clockType -->
<!-- $$$elapsed[overload1]$$$elapsed -->
<h3 class="fn" id="elapsed"><a name="elapsed"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QElapsedTimer::<span class="name">elapsed</span>() const</h3>
<p>Returns the number of milliseconds since this <a href="qelapsedtimer.html">QElapsedTimer</a> was last started.</p>
<p>Calling this function on a <a href="qelapsedtimer.html">QElapsedTimer</a> that is invalid results in undefined behavior.</p>
<p><b>See also </b><a href="qelapsedtimer.html#start">start</a>(), <a href="qelapsedtimer.html#restart">restart</a>(), <a href="qelapsedtimer.html#hasExpired">hasExpired</a>(), <a href="qelapsedtimer.html#isValid">isValid</a>(), and <a href="qelapsedtimer.html#invalidate">invalidate</a>().</p>
<!-- @@@elapsed -->
<!-- $$$hasExpired[overload1]$$$hasExpiredqint64 -->
<h3 class="fn" id="hasExpired"><a name="hasExpired"></a><span class="type">bool</span> QElapsedTimer::<span class="name">hasExpired</span>(<span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>timeout</i>) const</h3>
<p>Returns <code>true</code> if this <a href="qelapsedtimer.html">QElapsedTimer</a> has already expired by <i>timeout</i> milliseconds (that is, more than <i>timeout</i> milliseconds have elapsed). The value of <i>timeout</i> can be -1 to indicate that this timer does not expire, in which case this function will always return false.</p>
<p><b>See also </b><a href="qelapsedtimer.html#elapsed">elapsed</a>() and <a href="qdeadlinetimer.html">QDeadlineTimer</a>.</p>
<!-- @@@hasExpired -->
<!-- $$$invalidate[overload1]$$$invalidate -->
<h3 class="fn" id="invalidate"><a name="invalidate"></a><span class="type">void</span> QElapsedTimer::<span class="name">invalidate</span>()</h3>
<p>Marks this <a href="qelapsedtimer.html">QElapsedTimer</a> object as invalid.</p>
<p>An invalid object can be checked with <a href="qelapsedtimer.html#isValid">isValid</a>(). Calculations of timer elapsed since invalid data are undefined and will likely produce bizarre results.</p>
<p><b>See also </b><a href="qelapsedtimer.html#isValid">isValid</a>(), <a href="qelapsedtimer.html#start">start</a>(), and <a href="qelapsedtimer.html#restart">restart</a>().</p>
<!-- @@@invalidate -->
<!-- $$$isMonotonic[overload1]$$$isMonotonic -->
<h3 class="fn" id="isMonotonic"><a name="isMonotonic"></a><code>[static] </code><span class="type">bool</span> QElapsedTimer::<span class="name">isMonotonic</span>()</h3>
<p>Returns <code>true</code> if this is a monotonic clock, false otherwise. See the information on the different clock types to understand which ones are monotonic.</p>
<p><b>See also </b><a href="qelapsedtimer.html#clockType">clockType</a>() and <a href="qelapsedtimer.html#ClockType-enum">QElapsedTimer::ClockType</a>.</p>
<!-- @@@isMonotonic -->
<!-- $$$isValid[overload1]$$$isValid -->
<h3 class="fn" id="isValid"><a name="isValid"></a><span class="type">bool</span> QElapsedTimer::<span class="name">isValid</span>() const</h3>
<p>Returns <code>false</code> if the timer has never been started or invalidated by a call to <a href="qelapsedtimer.html#invalidate">invalidate</a>().</p>
<p><b>See also </b><a href="qelapsedtimer.html#invalidate">invalidate</a>(), <a href="qelapsedtimer.html#start">start</a>(), and <a href="qelapsedtimer.html#restart">restart</a>().</p>
<!-- @@@isValid -->
<!-- $$$msecsSinceReference[overload1]$$$msecsSinceReference -->
<h3 class="fn" id="msecsSinceReference"><a name="msecsSinceReference"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QElapsedTimer::<span class="name">msecsSinceReference</span>() const</h3>
<p>Returns the number of milliseconds between last time this <a href="qelapsedtimer.html">QElapsedTimer</a> object was started and its reference clock's start.</p>
<p>This number is usually arbitrary for all clocks except the <a href="qelapsedtimer.html#ClockType-enum">QElapsedTimer::SystemTime</a> 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).</p>
<p>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.</p>
<p><b>See also </b><a href="qelapsedtimer.html#clockType">clockType</a>() and <a href="qelapsedtimer.html#elapsed">elapsed</a>().</p>
<!-- @@@msecsSinceReference -->
<!-- $$$msecsTo[overload1]$$$msecsToconstQElapsedTimer& -->
<h3 class="fn" id="msecsTo"><a name="msecsTo"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QElapsedTimer::<span class="name">msecsTo</span>(const <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> &amp;<i>other</i>) const</h3>
<p>Returns the number of milliseconds between this <a href="qelapsedtimer.html">QElapsedTimer</a> and <i>other</i>. If <i>other</i> was started before this object, the returned value will be negative. If it was started later, the returned value will be positive.</p>
<p>The return value is undefined if this object or <i>other</i> were invalidated.</p>
<p><b>See also </b><a href="qelapsedtimer.html#secsTo">secsTo</a>() and <a href="qelapsedtimer.html#elapsed">elapsed</a>().</p>
<!-- @@@msecsTo -->
<!-- $$$nsecsElapsed[overload1]$$$nsecsElapsed -->
<h3 class="fn" id="nsecsElapsed"><a name="nsecsElapsed"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QElapsedTimer::<span class="name">nsecsElapsed</span>() const</h3>
<p>Returns the number of nanoseconds since this <a href="qelapsedtimer.html">QElapsedTimer</a> was last started.</p>
<p>Calling this function on a <a href="qelapsedtimer.html">QElapsedTimer</a> that is invalid results in undefined behavior.</p>
<p>On platforms that do not provide nanosecond resolution, the value returned will be the best estimate available.</p>
<p>This function was introduced in  Qt 4.8.</p>
<p><b>See also </b><a href="qelapsedtimer.html#start">start</a>(), <a href="qelapsedtimer.html#restart">restart</a>(), <a href="qelapsedtimer.html#hasExpired">hasExpired</a>(), and <a href="qelapsedtimer.html#invalidate">invalidate</a>().</p>
<!-- @@@nsecsElapsed -->
<!-- $$$restart[overload1]$$$restart -->
<h3 class="fn" id="restart"><a name="restart"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QElapsedTimer::<span class="name">restart</span>()</h3>
<p>Restarts the timer and returns the time elapsed since the previous start. This function is equivalent to obtaining the elapsed time with <a href="qelapsedtimer.html#elapsed">elapsed</a>() and then starting the timer again with <a href="qelapsedtimer.html#start">start</a>(), but it does so in one single operation, avoiding the need to obtain the clock value twice.</p>
<p>Calling this function on a <a href="qelapsedtimer.html">QElapsedTimer</a> that is invalid results in undefined behavior.</p>
<p>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:</p>
<pre class="cpp">

      <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> timer;

      <span class="type">int</span> count <span class="operator">=</span> <span class="number">1</span>;
      timer<span class="operator">.</span>start();
      <span class="keyword">do</span> {
          count <span class="operator">*</span><span class="operator">=</span> <span class="number">2</span>;
          slowOperation2(count);
      } <span class="keyword">while</span> (timer<span class="operator">.</span>restart() <span class="operator">&lt;</span> <span class="number">250</span>);

      <span class="keyword">return</span> count;

</pre>
<p><b>See also </b><a href="qelapsedtimer.html#start">start</a>(), <a href="qelapsedtimer.html#invalidate">invalidate</a>(), <a href="qelapsedtimer.html#elapsed">elapsed</a>(), and <a href="qelapsedtimer.html#isValid">isValid</a>().</p>
<!-- @@@restart -->
<!-- $$$secsTo[overload1]$$$secsToconstQElapsedTimer& -->
<h3 class="fn" id="secsTo"><a name="secsTo"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QElapsedTimer::<span class="name">secsTo</span>(const <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> &amp;<i>other</i>) const</h3>
<p>Returns the number of seconds between this <a href="qelapsedtimer.html">QElapsedTimer</a> and <i>other</i>. If <i>other</i> was started before this object, the returned value will be negative. If it was started later, the returned value will be positive.</p>
<p>Calling this function on or with a <a href="qelapsedtimer.html">QElapsedTimer</a> that is invalid results in undefined behavior.</p>
<p><b>See also </b><a href="qelapsedtimer.html#msecsTo">msecsTo</a>() and <a href="qelapsedtimer.html#elapsed">elapsed</a>().</p>
<!-- @@@secsTo -->
<!-- $$$start[overload1]$$$start -->
<h3 class="fn" id="start"><a name="start"></a><span class="type">void</span> QElapsedTimer::<span class="name">start</span>()</h3>
<p>Starts this timer. Once started, a timer value can be checked with <a href="qelapsedtimer.html#elapsed">elapsed</a>() or <a href="qelapsedtimer.html#msecsSinceReference">msecsSinceReference</a>().</p>
<p>Normally, a timer is started just before a lengthy operation, such as:</p>
<pre class="cpp">

      <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> timer;
      timer<span class="operator">.</span>start();

      slowOperation1();

      <a href="qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The slow operation took&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> timer<span class="operator">.</span>elapsed() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;milliseconds&quot;</span>;

</pre>
<p>Also, starting a timer makes it valid again.</p>
<p><b>See also </b><a href="qelapsedtimer.html#restart">restart</a>(), <a href="qelapsedtimer.html#invalidate">invalidate</a>(), and <a href="qelapsedtimer.html#elapsed">elapsed</a>().</p>
<!-- @@@start -->
<!-- $$$operator!=[overload1]$$$operator!=constQElapsedTimer& -->
<h3 class="fn" id="operator-not-eq"><a name="operator-not-eq"></a><span class="type">bool</span> QElapsedTimer::<span class="name">operator!=</span>(const <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> &amp;<i>other</i>) const</h3>
<p>Returns <code>true</code> if this object and <i>other</i> contain different times.</p>
<!-- @@@operator!= -->
<!-- $$$operator==[overload1]$$$operator==constQElapsedTimer& -->
<h3 class="fn" id="operator-eq-eq"><a name="operator-eq-eq"></a><span class="type">bool</span> QElapsedTimer::<span class="name">operator==</span>(const <span class="type"><a href="qelapsedtimer.html#QElapsedTimer">QElapsedTimer</a></span> &amp;<i>other</i>) const</h3>
<p>Returns <code>true</code> if this object and <i>other</i> contain the same time.</p>
<!-- @@@operator== -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>