Receptacle
 All Classes Files Functions Variables Pages
signal_counter.h
1 /*
2 
3 Copyright 2014 William Wedler
4 
5 This file is part of Receptacle
6 
7 Receptacle is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Receptacle is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with Receptacle. If not, see <http://www.gnu.org/licenses/>.
19 
20 */
21 
22 
23 // signal_counter.h
24 
25 #ifndef SIGNAL_COUNTER_H
26 #define SIGNAL_COUNTER_H
27 
28 #include <QObject>
29 
33 class SignalCounter : public QObject
34 {
35  Q_OBJECT
36 public:
42  SignalCounter(const QObject * object, const char * signal):c(0){
43  QObject::connect(object, signal, this, SLOT(increment()));
44  }
45 
50  int count(){return c;}
51 
52  void reset_count(){c=0;}
53 
54 signals:
55  void signal_received();
56 
57 private slots:
61  void increment(){c++; Q_EMIT signal_received();}
62 
63 protected:
64  int c;
65 
66 };
67 
68 #endif // SIGNAL_COUNTER_H
The SignalCounter class is a simplified version of QSignalSpy.
Definition: signal_counter.h:33
SignalCounter(const QObject *object, const char *signal)
SignalCounter constructor connects to the given signal and starts counting at 0.
Definition: signal_counter.h:42
int count()
Current count of signals that have been emitted.
Definition: signal_counter.h:50