NorMIT-nav  18.04
An IGT application
cxtestQueuedSignalListener.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXTESTQUEUEDSIGNALLISTENER_H_
13 #define CXTESTQUEUEDSIGNALLISTENER_H_
14 
15 #include "cxtestutilities_export.h"
16 #include <QObject>
17 
18 class QTimer;
19 class QEventLoop;
20 
21 namespace cxtest
22 {
23 
24 bool CXTESTUTILITIES_EXPORT waitForQueuedSignal(QObject* object, const char* signal, int maxWaitMilliSeconds = 100, bool silentAtArrive = false);
25 
34 class CXTESTUTILITIES_EXPORT QueuedSignalListener : public QObject
35 {
36  Q_OBJECT
37 
38 public:
39  QueuedSignalListener(QObject* object, const char* signal, int maxWaitMilliSeconds = 100);
40  virtual ~QueuedSignalListener();
41 
42  int exec();
43  bool timedOut();
44 
45 private slots:
46  void quit();
47 
48 private:
49  void createTimer(int maxWaitMilliSeconds);
50  void createEventLoop(QObject* object, const char* signal);
51 
52  QTimer* mTimer;
53  QEventLoop* mLoop;
54 
55  bool mTimedOut;
56 };
57 
58 
59 } /* namespace cxtest */
60 #endif /* CXTESTQUEUEDSIGNALLISTENER_H_ */
bool waitForQueuedSignal(QObject *object, const char *signal, int maxWaitMilliSeconds, bool silentAtArrive)
Object that waits for a signal to arrive from a given QObject. If this takes longer than a given time...