From e9a64615c8e18692a775765787f404266767260b Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 27 Mar 2017 14:34:38 -0400 Subject: Make qt wallet test compatible with qt4 Unlike Qt5, the Qt4 signals implementation doesn't allow a signal to be directly connected to a c++ lambda expression. Work around this by defining a Callback QObject with a virtual method that can forward calls to a closure. The Qt4 error was reported by Patrick Strateman in https://github.com/bitcoin/bitcoin/pull/10039#issuecomment-289248763 --- src/qt/callback.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/qt/callback.h (limited to 'src/qt/callback.h') diff --git a/src/qt/callback.h b/src/qt/callback.h new file mode 100644 index 0000000000..a8b593a652 --- /dev/null +++ b/src/qt/callback.h @@ -0,0 +1,30 @@ +#ifndef BITCOIN_QT_CALLBACK_H +#define BITCOIN_QT_CALLBACK_H + +#include + +class Callback : public QObject +{ + Q_OBJECT +public Q_SLOTS: + virtual void call() = 0; +}; + +template +class FunctionCallback : public Callback +{ + F f; + +public: + FunctionCallback(F f_) : f(std::move(f_)) {} + ~FunctionCallback() override {} + void call() override { f(this); } +}; + +template +FunctionCallback* makeCallback(F f) +{ + return new FunctionCallback(std::move(f)); +} + +#endif // BITCOIN_QT_CALLBACK_H -- cgit v1.2.3