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
This commit is contained in:
tt2468 2021-09-24 18:10:17 -07:00
parent 7a888c2f92
commit 78d02696d0
3 changed files with 35 additions and 0 deletions

16
src/utils/Compat.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "Compat.h"
Utils::Compat::StdFunctionRunnable::StdFunctionRunnable(std::function<void()> func) :
cb(std::move(func))
{
}
void Utils::Compat::StdFunctionRunnable::run()
{
cb();
}
QRunnable *Utils::Compat::CreateFunctionRunnable(std::function<void()> func)
{
return new Utils::Compat::StdFunctionRunnable(std::move(func));
}

18
src/utils/Compat.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <functional>
#include <QRunnable>
namespace Utils {
namespace Compat {
// Reimplement QRunnable for std::function. Retrocompatability for Qt < 5.15
class StdFunctionRunnable : public QRunnable {
std::function<void()> cb;
public:
StdFunctionRunnable(std::function<void()> func);
void run() override;
};
QRunnable *CreateFunctionRunnable(std::function<void()> func);
}
}

View File

@ -4,3 +4,4 @@
#include "Json.h"
#include "Obs.h"
#include "Platform.h"
#include "Compat.h"