문제

So I have a timer pretty much, but it doesnt count seconds, it just counts up but not in the same speed as a normal second. The application works just fine, but as i said, it counts but it doesnt count in real seconds. So question is how to change the speed. I'm also adding hundreth of a second to this.

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

Display:

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
        }
}
도움이 되었습니까?

해결책

In Javascript, the window.setInterval() and window.setTimeout() functions are rarely called at the exact times specified. You would be better served to check the actual time in every call to your function, as this will give you the actual system time:

var currentdate = new Date();
var hours = currentdate.getHours();
var minutes = currentdate.getMinutes();
var seconds = currentdate.getSeconds();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top