You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

callback.h 538B

123456789101112131415161718192021222324252627282930
  1. #ifndef STARWELS_QT_CALLBACK_H
  2. #define STARWELS_QT_CALLBACK_H
  3. #include <QObject>
  4. class Callback : public QObject
  5. {
  6. Q_OBJECT
  7. public Q_SLOTS:
  8. virtual void call() = 0;
  9. };
  10. template <typename F>
  11. class FunctionCallback : public Callback
  12. {
  13. F f;
  14. public:
  15. FunctionCallback(F f_) : f(std::move(f_)) {}
  16. ~FunctionCallback() override {}
  17. void call() override { f(this); }
  18. };
  19. template <typename F>
  20. FunctionCallback<F>* makeCallback(F f)
  21. {
  22. return new FunctionCallback<F>(std::move(f));
  23. }
  24. #endif // STARWELS_QT_CALLBACK_H