2017-02-17 62 views
1

我有方法。此方法具有静态QTime,但如果发生某些情况,我想重置此值。静态Qtime默认值

static QTime time(QTime::currentTime()); 

// calculate two new data points: 
double key = time.elapsed()/1000; 

static double lastPointKey = 0; 

if(newPlot == true){ 
    // like tihs key = 0 ;   
    // lastPointKey = 0 ; 
} 

回答

1

使用QTime::restart()方法来重置您的计时器。

另外,请看QElapsedTimer班。它有一个类似的API(elapsed(),restart()等),但是您可能会发现它更适合您的情况。从文档:

QElapsedTimer将使用该平台的单调参考时钟在所有支持的平台 。这有 额外的好处,即QElapsedTimer不受时间调整, ,如用户纠正时间。也不像QTimeQElapsedTimer 对时区设置中的更改有效,例如夏令时 时段。