2014-05-04 80 views
0

所以我有一個計時器,但它不計算秒,它只是數了起來,但沒有像普通秒一樣的速度。該應用程序工作得很好,但正如我所說,它很重要,但它並不在真正的秒數。所以問題是如何改變速度。我也爲此添加了一秒鐘的洪流。javascript不算正確

Timer { 
     id:ticker 
     interval: 100; running: false; repeat: true; 
     onTriggered: point.countIn() 
    } 

顯示:

import QtQuick 2.1 

Rectangle { 
    id : display 
    width : 320 ; height: 280 
    color: "#fff" 

    function countIn() 
    { 
     if (seconds == 59) 
     { 
      seconds = 0; 
      countOut(); 
     } 
     else 
      seconds++; 
    } 
    function reset() 
    { 
     seconds = 0; 
    } 

    property int seconds 

    signal countOut 
    property int pointSize : 80 

    function formatOutput() 
    { 
     if (seconds < 10) 
      return '0' + seconds 
     else 
      return seconds 
    } 


    Text { 
      text: formatOutput() 
      font.pointSize: pointSize; font.bold: true 
      font.family: "Courier" 
      anchors.centerIn: parent 
     } 
} 

回答

1

在JavaScript中,window.setInterval()window.setTimeout()功能很少在指定的確切時間調用。你會更好地檢查每次打電話給你的功能的實際時間,因爲這會給你實際的系統時間:

var currentdate = new Date(); 
var hours = currentdate.getHours(); 
var minutes = currentdate.getMinutes(); 
var seconds = currentdate.getSeconds(); 
+0

Couldnt完全得到它與這..工作但非常感謝。當我有更多的時間時,稍後再研究一下吧! :) –

+0

Nvm,修復它!再次感謝您的幫助! –

+0

通常計時器對於這樣的時鐘足夠精確,我不確定您是否知道這個明顯的錯誤,但是您的間隔設置爲100ms而不是1000ms!?我的意思是在這個問題上,我只是在這裏寫評論,因爲這是被接受的答案。 – Xander