Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
timers.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QChronoTimer>
5#include <QObject>
6#include <QTimer>
7
8using namespace std::chrono;
9
10class Foo : public QObject
11{
12public:
13 Foo();
14};
15
17{
18//! [0]
19 QTimer *timer = new QTimer(this);
20//! [0] //! [1]
21 connect(timer, &QTimer::timeout, this, &Foo::updateCaption);
22//! [1] //! [2]
23 timer->start(1000);
24//! [2]
25
26//! [3]
27 QTimer::singleShot(200, this, &Foo::updateCaption);
28//! [3]
29
30 {
31 // ZERO-CASE
32//! [4]
33 QTimer *timer = new QTimer(this);
34//! [4] //! [5]
35 connect(timer, &QTimer::timeout, this, &Foo::processOneThing);
36//! [5] //! [6]
37 timer->start();
38//! [6]
39 }
40}
41
42// QTimer
43class MyWidget : QObject
44{
45 MyWidget()
46 {
47//! [qtimer-singleshot]
48 MyWidget widget;
49 QTimer::singleShot(200ms, &widget, &MyWidget::updateCaption);
50//! [qtimer-singleshot]
51
52//! [zero-timer]
53 // The default interval is 0ns
54 QTimer *timer = new QTimer(this);
55 connect(timer, &QTimer::timeout, this, &MyWidget::processOneThing);
56 timer->start();
57//! [zero-timer]
58
59 {
60//! [timer-interval-in-ctor]
61 QTimer *timer = new QTimer(1s, this);
62 connect(timer, &QTimer::timeout, this, &MyWidget::processOneThing);
63 timer->start();
64//! [timer-interval-in-ctor]
65 }
66
67 {
68//! [timer-setinterval]
69 auto *timer = new QTimer(this);
70 connect(timer, &QTimer::timeout, this, &MyWidget::processOneThing);
71 timer->setInterval(1s);
72 timer->start();
73//! [timer-setinterval]
74 }
75
76 {
77//! [qchronotimer-interval-in-ctor]
78 auto *timer = new QChronoTimer(1s, this);
79 connect(timer, &QChronoTimer::timeout, this, &MyWidget::processOneThing);
80 timer->start();
81//! [qchronotimer-interval-in-ctor]
82 }
83
84 {
85//! [qchronotimer-setinterval]
86 QChronoTimer *timer = new QChronoTimer(this);
87 connect(timer, &QChronoTimer::timeout, this, &MyWidget::processOneThing);
88 timer->setInterval(1s);
89 timer->start();
90//! [qchronotimer-setinterval]
91 }
92 }
93
94public Q_SLOTS:
96};
97
98int main()
99{
100}
int main()
[open]
Foo()
Definition timers.cpp:16