静态 Qtime 默认值

Static Qtime Default Value

我有办法。此方法具有静态 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 ;
}

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

此外,请查看 QElapsedTimer class. It has a similar API (elapsed(), restart() 等),但您可能会发现它更适合您的情况。来自文档:

QElapsedTimer will use the platform's monotonic reference clock in all platforms that support it. This has the added benefit that QElapsedTimer is immune to time adjustments, such as the user correcting the time. Also unlike QTime, QElapsedTimer is immune to changes in the timezone settings, such as daylight-saving periods.