-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.cpp
More file actions
70 lines (42 loc) · 1.36 KB
/
example.cpp
File metadata and controls
70 lines (42 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "example.h"
#include <QTimer>
#include <QDebug>
#include <QMetaObject>
/**
* Constructor creates some QTimers then uses connectSlotsByName to
* set up the connections instead of QObject::connect(). Note that we
* don't need to store QTimer*'s to do this, which could be handy in
* some applications.
*/
Example::Example (QObject *parent) :
QObject(parent)
{
setupTimer(1100, "timer1");
setupTimer(1700, "timer2");
setupTimer(2300, "timer3");
// We don't create a timer named "notimer", this is to show the type
// of warning connectSlotsByName() will generate if no matching object
// or signal is found.
QMetaObject::connectSlotsByName(this);
}
/**
* Convenience function to create a periodic QTimer, set its name, and
* start it with the specified interval (milliseconds).
*/
void Example::setupTimer (int interval, QString name) {
QTimer *timer = new QTimer(this); // <- Part of this object tree.
timer->setObjectName(name); // <- Name will match slot names.
timer->start(interval);
}
void Example::on_timer1_timeout () {
qDebug("timer1 timeout");
}
void Example::on_timer2_timeout () {
qDebug("timer2 timeout");
}
void Example::on_timer3_timeout () {
qDebug("timer3 timeout");
}
void Example::on_notimer_timeout () {
// In this example, this slot won't be connected to anything.
}