Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
8
using
namespace
std::chrono;
9
10
class
Foo
:
public
QObject
11
{
12
public
:
13
Foo
();
14
};
15
16
Foo
::
Foo
()
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
43
class
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
94
public
Q_SLOTS
:
95
void
processOneThing
();
96
};
97
98
int
main
()
99
{
100
}
MyWidget
[24]
Definition
src_corelib_kernel_qobject.cpp:264
main
int main()
[open]
Definition
doc_src_objecttrees.cpp:7
Foo
[54]
Definition
src_corelib_global_qglobal.cpp:554
Foo::Foo
Foo()
Definition
timers.cpp:16
qtbase
src
corelib
doc
snippets
timers
timers.cpp
Generated on
for Qt by
1.18.0