Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
main.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
#include <QtCore>
4
5
void
slowOperation1
()
6
{
7
static
char
buf
[256];
8
for
(
int
i
= 0;
i
< (1<<20); ++
i
)
9
buf
[
i
%
sizeof
buf
] =
i
;
10
}
11
12
void
slowOperation2
(
int
) {
slowOperation1
(); }
13
14
void
startExample
()
15
{
17
QElapsedTimer
timer
;
18
timer
.
start
();
19
20
slowOperation1
();
21
22
qDebug
() <<
"The slow operation took"
<<
timer
.elapsed() <<
"milliseconds"
;
24
}
25
27
void
executeSlowOperations
(
int
timeout
)
28
{
29
QElapsedTimer
timer
;
30
timer
.
start
();
31
slowOperation1
();
32
33
int
remainingTime =
timeout
-
timer
.elapsed();
34
if
(remainingTime > 0)
35
slowOperation2
(remainingTime);
36
}
38
40
void
executeOperationsForTime
(
int
ms)
41
{
42
QElapsedTimer
timer
;
43
timer
.
start
();
44
45
while
(!
timer
.hasExpired(ms))
46
slowOperation1
();
47
}
49
50
int
restartExample
()
51
{
53
QElapsedTimer
timer
;
54
55
int
count
= 1;
56
timer
.
start
();
57
do
{
58
count
*= 2;
59
slowOperation2
(
count
);
60
}
while
(
timer
.restart() < 250);
61
62
return
count
;
64
}
65
66
int
main
(
int
argc,
char
**argv)
67
{
68
QCoreApplication
app
(argc, argv);
69
70
startExample
();
71
restartExample
();
72
executeSlowOperations
(5);
73
executeOperationsForTime
(5);
74
}
QCoreApplication
\inmodule QtCore
Definition
qcoreapplication.h:48
QElapsedTimer
\inmodule QtCore
Definition
qelapsedtimer.h:15
QTimer::start
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition
qtimer.cpp:241
i
i
[1]
Definition
doc_src_containers.cpp:169
main
int main()
[0]
Definition
doc_src_objecttrees.cpp:5
qDebug
#define qDebug
[1]
Definition
qlogging.h:164
count
GLenum GLenum GLsizei count
Definition
qopengles2ext.h:150
timeout
GLbitfield GLuint64 timeout
[4]
Definition
qopengles2ext.h:1029
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition
qopengles2ext.h:151
executeSlowOperations
void executeSlowOperations(int timeout)
[1]
Definition
main.cpp:27
executeOperationsForTime
void executeOperationsForTime(int ms)
[1]
Definition
main.cpp:40
startExample
void startExample()
Definition
main.cpp:14
slowOperation2
void slowOperation2(int)
Definition
main.cpp:12
slowOperation1
void slowOperation1()
Definition
main.cpp:5
restartExample
int restartExample()
[2]
Definition
main.cpp:50
timer
QTimer * timer
[3]
Definition
src_corelib_kernel_qobject.cpp:23
app
QApplication app(argc, argv)
[0]
qtbase
src
corelib
doc
snippets
qelapsedtimer
main.cpp
Generated by
1.10.0