<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # QElapsedTimer Class Reference ## [[QtCore](index.htm) module] 該QElapsedTimer類提供了一種快速的方法來計算經過的時間。[More...](#details) ### Types * `enum ClockType { SystemTime, MonotonicClock, TickCounter, MachAbsoluteTime, PerformanceCounter }` ### Methods * `__init__ (self)` * `__init__ (self, QElapsedTimer)` * `int elapsed (self)` * `bool hasExpired (self, int?timeout)` * `invalidate (self)` * `bool isValid (self)` * `int msecsSinceReference (self)` * `int msecsTo (self, QElapsedTimer?other)` * `int nsecsElapsed (self)` * `int restart (self)` * `int secsTo (self, QElapsedTimer?other)` * `start (self)` ### Static Methods * `ClockType clockType ()` * `bool isMonotonic ()` ### Special Methods * `bool __eq__ (self, QElapsedTimer?other)` * `bool __ge__ (self, QElapsedTimer?v2)` * `bool __lt__ (self, QElapsedTimer?v2)` * `bool __ne__ (self, QElapsedTimer?other)` * * * ## Detailed Description 該QElapsedTimer類提供了一種快速的方法來計算經過的時間。 該QElapsedTimer類通常用于快速計算多少時間兩個事件之間經過。它的API是類似的[QTime](qtime.html),使被使用,可以很容易的移植到新類的代碼。 然而,不像[QTime](qtime.html), QElapsedTimer嘗試盡可能使用單調的時鐘。這意味著它不可能QElapsedTimer對象轉換為人類可讀的時間。 典型用例的類是確定多少時間是如何度過在一個緩慢的操作。這種情況下最簡單的例子是用于調試目的,如下面的例子: ``` QElapsedTimer timer; timer.start(); slowOperation1(); qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds"; ``` 在這個例子中,定時器是由一個呼叫開始[start](qelapsedtimer.html#start)()和定時器計時是由計算[elapsed](qelapsedtimer.html#elapsed)()函數。 所經過的時間,也可用于重新計算可用于其它操作所需的時間,之后,第一個是完整的。當執行必須在一定的時間內完成,這是有用的,但需要幾個步驟。該`waitFor`在類型的功能[QIODevice](qiodevice.html)和它的子類是需要這樣的好例子。在這種情況下,代碼可能如下: ``` void executeSlowOperations(int timeout) { QElapsedTimer timer; timer.start(); slowOperation1(); int remainingTime = timeout - timer.elapsed(); if (remainingTime > 0) slowOperation2(remainingTime); } ``` 另一個用例是執行某種操作的具體時間片。為此, QElapsedTimer提供[hasExpired](qelapsedtimer.html#hasExpired)()的便利功能,它可以被用于確定是否一個特定的毫秒已經過去了: ``` void executeOperationsForTime(int ms) { QElapsedTimer timer; timer.start(); while (!timer.hasExpired(ms)) slowOperation1(); } ``` ### Reference clocks QElapsedTimer將使用該平臺的單調參考時鐘在所有支持它的平臺上(見[QElapsedTimer.isMonotonic](qelapsedtimer.html#isMonotonic)())。這具有額外的好處, QElapsedTimer不受時間的調整,如在用戶校正的時間。也不像[QTime](qtime.html), QElapsedTimer是免疫的變化時區設置,如日光節約時間。 另一方面,這意味著QElapsedTimer值只能與使用相同的參考其他值進行比較。這是尤其如此,如果因為參考的時間是從QElapsedTimer對象(摘錄[QElapsedTimer.msecsSinceReference](qelapsedtimer.html#msecsSinceReference)( ) )和序列化。這些值不應該在網絡上交換或保存到磁盤上,因為沒有告訴計算機節點接收的數據是否是相同的一個始發它,或者如果它已經重新啟動。 它是,但是,可以在同一臺機器上運行的其他進程,條件是它們也使用相同的參考時鐘交換價值。 QElapsedTimer將始終使用同一個時鐘,因此它的安全與來自另一個進程的值來在同一臺機器進行比較。如果比較其他的API產生的值,你應該檢查所使用的時鐘是相同的QElapsedTimer (見[QElapsedTimer.clockType](qelapsedtimer.html#clockType)())。 #### 32-bit overflows 一些該QElapsedTimer有一個有限的范圍和擊球的上限(通常為32位)后可能溢出的時鐘。 QElapsedTimer處理這個溢出問題,并提出了一致的時機。然而,由于提取從QElapsedTimer參考時間時,在同一機器兩個不同的過程可能有不同的理解的多少時間實際上已經過去了。 在其上的信息時鐘類型可能會溢出,以及如何修復這個問題將隨著時鐘類型的記錄。 * * * ## Type Documentation ``` QElapsedTimer.ClockType ``` 這個枚舉包含了不同的時鐘類型[QElapsedTimer](qelapsedtimer.html)可以使用。 [QElapsedTimer](qelapsedtimer.html)將始終使用相同的時鐘類型在特定的機器,所以這個值的程序的生命周期內不會改變。它被設置成使得[QElapsedTimer](qelapsedtimer.html)可以與其它非Qt的實現中使用,以保證該相同的參考時鐘被使用。 | Constant | Value | Description | | --- | --- | --- | | `QElapsedTimer.SystemTime` | `0` | 人類可讀的系統時間。這個時鐘是不是單調的。 | | `QElapsedTimer.MonotonicClock` | `1` | 該系統的單調時鐘,通常是在Unix系統中找到。這個時鐘是單調的,并且不會溢出。 | | `QElapsedTimer.TickCounter` | `2` | 該系統的時鐘計數器,在Windows和Symbian系統中使用。這個時鐘可能會溢出。 | | `QElapsedTimer.MachAbsoluteTime` | `3` | 在Mach內核的絕對時間( Mac OS X中) 。這個時鐘是單調的,并且不會溢出。 | | `QElapsedTimer.PerformanceCounter` | `4` | Windows提供的高分辨率性能計數器。這個時鐘是單調的,并且不會溢出。 | ##### SystemTime 系統時間時鐘是純粹的實時性,自1970年1月1日在0:00 UTC毫秒表示。它等價于C和POSIX的返回值`time`功能,以毫秒為單位加入。這個時鐘類型目前只用在不支持單調時鐘Unix系統(見下文)。 這是唯一的非單調時鐘[QElapsedTimer](qelapsedtimer.html)可以使用。 ##### MonotonicClock 這是系統的單調時鐘,因為任意一個點過去以毫秒為單位。這種類型的時鐘是用在哪些支持POSIX的單調時鐘( Unix系統`_POSIX_MONOTONIC_CLOCK`) 。 這個時鐘不會溢出。 ##### TickCounter 滴答計數器的時鐘類型是基于系統的或處理器的時鐘計數器,乘以一個刻度的持續時間。這個時鐘類型用于在Windows和Symbian平臺。如果高精度的性能計數器,可以在Windows上,`PerformanceCounter`時鐘類型來代替。 該TickCounter時鐘類型是可能會溢出的唯一時鐘類型。 Windows Vista和Windows Server 2008中支持擴展的64位時鐘計數器,它允許避免溢出。 在Windows系統中,時鐘后2 ^ 32毫秒,這相當于大約49.7天溢出。這意味著,由于基準時間兩個過程的推算可能是由不同的2 ^ 32毫秒的倍數。當比較這些值,它的建議,高32位的毫秒計數的被屏蔽掉。 在Symbian系統中,溢出發生后2 ^ 32的刻度,這期間可以從平臺的HAL使用恒定HAL.ENanoTickPeriod獲得的。在比較過程之間的值,有必要由蜱的持續時間來劃分值和屏蔽掉的高32位。 ##### MachAbsoluteTime 這個時鐘類型是基于馬赫內核,如在Mac OS X發現這個時鐘類型是從MonotonicClock單獨列示,因為Mac OS X是還涉及了UNIX系統,并且可以支持一個POSIX單調時鐘值呈現不同的絕對時間從馬赫絕對時間。 這個時鐘是單調的,并且不會溢出。 ##### PerformanceCounter 這個時鐘使用Windows功能`QueryPerformanceCounter`和`QueryPerformanceFrequency`訪問系統的高精度性能計數器。由于在所有的系統上,此計數器可能不可用,[QElapsedTimer](qelapsedtimer.html)將回落至`TickCounter`時鐘自動地,如果該時鐘不能使用。 這個時鐘是單調的,并且不會溢出。 **See also** [clockType](qelapsedtimer.html#clockType)()和[isMonotonic](qelapsedtimer.html#isMonotonic)( ) 。 * * * ## Method Documentation ``` QElapsedTimer.__init__ (self) ``` ``` QElapsedTimer.__init__ (self, QElapsedTimer) ``` ``` ClockType QElapsedTimer.clockType () ``` [](qelapsedtimer.html#ClockType-enum) [返回時鐘類型,這](qelapsedtimer.html#ClockType-enum)[QElapsedTimer](qelapsedtimer.html)實現使用。 **See also** [isMonotonic](qelapsedtimer.html#isMonotonic)( ) 。 ``` int QElapsedTimer.elapsed (self) ``` 返回的毫秒數,因為這[QElapsedTimer](qelapsedtimer.html)上次啟動。在調用此函數[QElapsedTimer](qelapsedtimer.html)這被認定無效,將導致不確定的結果。 **See also** [start](qelapsedtimer.html#start)( )[restart](qelapsedtimer.html#restart)( )[hasExpired](qelapsedtimer.html#hasExpired)()和[invalidate](qelapsedtimer.html#invalidate)( ) 。 ``` bool QElapsedTimer.hasExpired (self, int?timeout) ``` 返回True如果[QElapsedTimer](qelapsedtimer.html)已經過期了_timeout_毫秒(即,多于_timeout_毫秒已經過去了) 。價值_timeout_可以是-1 ,表明該計時器未到期,在這種情況下,該功能將始終返回False 。 **See also** [elapsed](qelapsedtimer.html#elapsed)( ) 。 ``` QElapsedTimer.invalidate (self) ``` 這個商標[QElapsedTimer](qelapsedtimer.html)對象為無效。 一個無效的對象可以進行檢查[isValid](qelapsedtimer.html#isValid)( ) 。定時器的計算距今無效數據是不確定的,可能會產生奇特的效果。 **See also** [isValid](qelapsedtimer.html#isValid)( )[start](qelapsedtimer.html#start)()和[restart](qelapsedtimer.html#restart)( ) 。 ``` bool QElapsedTimer.isMonotonic () ``` 返回True如果這是一個單調的時鐘,否則返回False。看到在不同的時鐘類型,了解哪些是單調的信息。 **See also** [clockType](qelapsedtimer.html#clockType)()和[QElapsedTimer.ClockType](qelapsedtimer.html#ClockType-enum)。 ``` bool QElapsedTimer.isValid (self) ``` 返回False,如果這個對象是無效通過調用[invalidate](qelapsedtimer.html#invalidate)() ,并沒有被自啟動。 **See also** [invalidate](qelapsedtimer.html#invalidate)( )[start](qelapsedtimer.html#start)()和[restart](qelapsedtimer.html#restart)( ) 。 ``` int QElapsedTimer.msecsSinceReference (self) ``` 返回毫秒的最后一次這樣的數[QElapsedTimer](qelapsedtimer.html)對象開始,其參考時鐘的開始。 這個數字通常是任意的所有時鐘的除外[QElapsedTimer.SystemTime](qelapsedtimer.html#ClockType-enum)時鐘。對于時鐘類型,這個數字是毫秒自1970年1月1日在0:00 UTC的數量(即,它是表示以毫秒為單位的Unix時間) 。 **See also** [clockType](qelapsedtimer.html#clockType)()和[elapsed](qelapsedtimer.html#elapsed)( ) 。 ``` int QElapsedTimer.msecsTo (self, QElapsedTimer?other) ``` 返回毫秒這之間的數[QElapsedTimer](qelapsedtimer.html)和_other_。如果_other_這個對象之前開始,返回值將是積極的。如果是起步較晚,返回值將是負數。 返回值是不確定的,如果這個對象或_other_已失效。 **See also** [secsTo](qelapsedtimer.html#secsTo)()和[elapsed](qelapsedtimer.html#elapsed)( ) 。 ``` int QElapsedTimer.nsecsElapsed (self) ``` 返回納秒數,因為這[QElapsedTimer](qelapsedtimer.html)上次啟動。在調用此函數[QElapsedTimer](qelapsedtimer.html)這被認定無效,將導致不確定的結果。 在不提供納秒分辨率的平臺,返回的值將是現有的最佳估計。 此功能被引入Qt的4.8 。 **See also** [start](qelapsedtimer.html#start)( )[restart](qelapsedtimer.html#restart)( )[hasExpired](qelapsedtimer.html#hasExpired)()和[invalidate](qelapsedtimer.html#invalidate)( ) 。 ``` int QElapsedTimer.restart (self) ``` 重新啟動定時器,并返回自上一次開始所經過的時間。此函數等同于獲得的經過時間以[elapsed](qelapsedtimer.html#elapsed)( ) ,然后重新啟動定時器[start](qelapsedtimer.html#start)() ,但它這樣做在一個單一的操作中,避免了需要獲得時鐘值的兩倍。 下面的例子演示了如何使用這個功能來校準參數,以一個緩慢的操作(例如,迭代次數),因此這種操作至少需要250毫秒: ``` [QElapsedTimer](qelapsedtimer.html) timer; int count = 1; timer.start(); do { count *= 2; slowOperation2(count); } while (timer.restart() < 250); return count; ``` **See also** [start](qelapsedtimer.html#start)( )[invalidate](qelapsedtimer.html#invalidate)()和[elapsed](qelapsedtimer.html#elapsed)( ) 。 ``` int QElapsedTimer.secsTo (self, QElapsedTimer?other) ``` 返回秒這之間的數[QElapsedTimer](qelapsedtimer.html)和_other_。如果_other_這個對象之前開始,返回值將是積極的。如果是起步較晚,返回值將是負數。 返回值是不確定的,如果這個對象或_other_已失效。 **See also** [msecsTo](qelapsedtimer.html#msecsTo)()和[elapsed](qelapsedtimer.html#elapsed)( ) 。 ``` QElapsedTimer.start (self) ``` 啟動此定時器。一旦開始,一個計時器的值可以與被檢查[elapsed](qelapsedtimer.html#elapsed)()或[msecsSinceReference](qelapsedtimer.html#msecsSinceReference)( ) 。 通常情況下,一個定時器被啟動只是一個冗長的操作,如前: ``` [QElapsedTimer](qelapsedtimer.html) timer; timer.start(); slowOperation1(); qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds"; ``` 此外,啟動定時器使它再次有效。 **See also** [restart](qelapsedtimer.html#restart)( )[invalidate](qelapsedtimer.html#invalidate)()和[elapsed](qelapsedtimer.html#elapsed)( ) 。 ``` bool QElapsedTimer.__eq__ (self, QElapsedTimer?other) ``` ``` bool QElapsedTimer.__ge__ (self, QElapsedTimer?v2) ``` ``` bool QElapsedTimer.__lt__ (self, QElapsedTimer?v2) ``` ``` bool QElapsedTimer.__ne__ (self, QElapsedTimer?other) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看