2017-02-17 86 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 對時區設置中的更改有效,例如夏令時 時段。