MythTV  master
SlotRelayer.h
Go to the documentation of this file.
1 #ifndef _SLOTRELAYER_H_
2 #define _SLOTRELAYER_H_
3 
4 #include <QObject>
5 class QString;
6 
7 /* This is a simple class that relays a QT slot to a function pointer.
8  * Useful when you have a relativly small app like mythcommflag that you
9  * don't want to wrap inside a QObject enheriting class.
10  *
11  * Unfortunattely QT does not allow this class to be templatized for all
12  * possible parameter types, so manual labor is in order if you need types other
13  * than the ones I made here
14  */
15 
16 class SlotRelayer : public QObject
17 {
18  Q_OBJECT
19 
20  public:
21  explicit SlotRelayer(void (*fp_in)(const QString&)) : m_fpQstring(fp_in) {}
22  explicit SlotRelayer(void (*fp_in)()) : m_fpVoid(fp_in) {};
23 
24  public slots:
25  void relay(const QString& arg) {if (m_fpQstring) m_fpQstring(arg);}
26  void relay() {if (m_fpVoid) m_fpVoid();}
27 
28  private:
29  ~SlotRelayer() override = default;
30  void (*m_fpQstring)(const QString&) { nullptr };
31  void (*m_fpVoid)() { nullptr };
32 };
33 
34 #endif
35 
36 
37 /* vim: set expandtab tabstop=4 shiftwidth=4: */
unsigned int slots[4]
Definition: element.c:38
void(* m_fpVoid)()
Definition: SlotRelayer.h:31
void relay()
Definition: SlotRelayer.h:26
void relay(const QString &arg)
Definition: SlotRelayer.h:25
SlotRelayer(void(*fp_in)())
Definition: SlotRelayer.h:22
void(* m_fpQstring)(const QString &)
Definition: SlotRelayer.h:30
~SlotRelayer() override=default
SlotRelayer(void(*fp_in)(const QString &))
Definition: SlotRelayer.h:21