From 78d02696d00350c9e1e08cbcc9aa2fed43999e7a Mon Sep 17 00:00:00 2001 From: tt2468 Date: Fri, 24 Sep 2021 18:10:17 -0700 Subject: [PATCH] Utils: Add retrocompatability header QRunnable::create was added in Qt 5.15, but Ubuntu still uses 5.12. This reimplements that functionality until Ubuntu moves to >= 5.15 --- src/utils/Compat.cpp | 16 ++++++++++++++++ src/utils/Compat.h | 18 ++++++++++++++++++ src/utils/Utils.h | 1 + 3 files changed, 35 insertions(+) create mode 100644 src/utils/Compat.cpp create mode 100644 src/utils/Compat.h diff --git a/src/utils/Compat.cpp b/src/utils/Compat.cpp new file mode 100644 index 00000000..f42939b0 --- /dev/null +++ b/src/utils/Compat.cpp @@ -0,0 +1,16 @@ +#include "Compat.h" + +Utils::Compat::StdFunctionRunnable::StdFunctionRunnable(std::function func) : + cb(std::move(func)) +{ +} + +void Utils::Compat::StdFunctionRunnable::run() +{ + cb(); +} + +QRunnable *Utils::Compat::CreateFunctionRunnable(std::function func) +{ + return new Utils::Compat::StdFunctionRunnable(std::move(func)); +} diff --git a/src/utils/Compat.h b/src/utils/Compat.h new file mode 100644 index 00000000..4b8d11a4 --- /dev/null +++ b/src/utils/Compat.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace Utils { + namespace Compat { + // Reimplement QRunnable for std::function. Retrocompatability for Qt < 5.15 + class StdFunctionRunnable : public QRunnable { + std::function cb; + public: + StdFunctionRunnable(std::function func); + void run() override; + }; + + QRunnable *CreateFunctionRunnable(std::function func); + } +} diff --git a/src/utils/Utils.h b/src/utils/Utils.h index 4948362c..76ff4793 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -4,3 +4,4 @@ #include "Json.h" #include "Obs.h" #include "Platform.h" +#include "Compat.h"