Files
Obsidian-Main/21.01. Programming/QT/timer.md

20 lines
460 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
使用QTimer來反覆執行工作。
QTimer可以單次執行也可以多次執行。
使用概念如下:
1. 建立 QTimer 物件,例如叫做 timer。
2. 連接QTimer的timeout signal到你的反應 function
3. 呼叫 timer->start()
Example:
```cpp
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
```
QTimer可以單次執行
```cpp
QTimer::singleShot(200, this, SLOT(update());
```