Browse Source
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 <patrick.strateman@gmail.com> in https://github.com/bitcoin/bitcoin/pull/10039#issuecomment-2892487630.15
Russell Yanofsky
8 years ago
3 changed files with 37 additions and 5 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
#ifndef BITCOIN_QT_CALLBACK_H |
||||
#define BITCOIN_QT_CALLBACK_H |
||||
|
||||
#include <QObject> |
||||
|
||||
class Callback : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
public Q_SLOTS: |
||||
virtual void call() = 0; |
||||
}; |
||||
|
||||
template <typename F> |
||||
class FunctionCallback : public Callback |
||||
{ |
||||
F f; |
||||
|
||||
public: |
||||
FunctionCallback(F f_) : f(std::move(f_)) {} |
||||
~FunctionCallback() override {} |
||||
void call() override { f(this); } |
||||
}; |
||||
|
||||
template <typename F> |
||||
FunctionCallback<F>* makeCallback(F f) |
||||
{ |
||||
return new FunctionCallback<F>(std::move(f)); |
||||
} |
||||
|
||||
#endif // BITCOIN_QT_CALLBACK_H
|
Loading…
Reference in new issue