Qt 5.10 Book Examples
chapter38
ThreadSignal
main.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// main.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtWidgets>
12
13
// ======================================================================
14
class
MyThread
:
public
QThread {
15
Q_OBJECT
16
17
public
:
18
void
run
()
19
{
20
for
(
int
i = 0; i <= 100; ++i) {
21
usleep(100000);
22
emit
progress
(i);
23
}
24
}
25
26
signals:
27
void
progress
(
int
);
28
};
29
30
// ----------------------------------------------------------------------
31
int
main
(
int
argc,
char
** argv)
32
{
33
QApplication app(argc, argv);
34
QProgressBar prb;
35
MyThread
thread;
36
37
QObject::connect(&thread, SIGNAL(progress(
int
)),
38
&prb, SLOT(setValue(
int
))
39
);
40
41
prb.show();
42
43
thread.start();
44
45
return
app.exec();
46
}
47
48
#include "main.moc"
main
int main(int argc, char **argv)
Definition:
main.cpp:15
MyThread
Definition:
main.cpp:37
MyThread::progress
void progress(int)
MyThread::run
void run()
Definition:
main.cpp:18
Generated by
1.8.14