QTimer類提供了重復和單次觸發信號的定時器。
QTimer類為定時器提供了一個高級別的編程接口。很容易使用:首先,創建一個QTimer,連接timeout()信號到適當的槽函數,並調用start(),然后在恆定的時間間隔會發射timeout()信號。
注意:當QTimer的父對象被銷毀時,它也會被自動銷毀。
詳細說明:
在Qt之模擬時鍾中,1秒(1000毫秒)更新一次:
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
start()之后,每秒都會調用update()。
可以通過設置setSingleShot(true)來讓定時器只執行一次。也可以使用靜態函數QTimer::singleShot():
QTimer::singleShot(200, this, SLOT(updateCaption()));
原文:https://blog.csdn.net/liang19890820/article/details/51789796