Commit 58a3007f authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Workaround a lack of std::function support in QThreadPool < 5.15

QThreadPool::start(std::function) was only introduced in Qt 5.15. This
adds a workaround (basically importing the class from Qt 5.15) for
earlier Qt versions.
parent f7064614
......@@ -6,7 +6,7 @@ set(PROJECT_VERSION "5.19.80")
set(PROJECT_VERSION_MAJOR 5)
# check with non-Plasma consumers (e.g. KDevelop) before bumping these versions
set(QT_MIN_VERSION "5.15.0")
set(QT_MIN_VERSION "5.14.0")
set(KF5_MIN_VERSION "5.66.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
......
......@@ -32,6 +32,21 @@
using namespace KSysGuard;
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
class FunctionRunnable : public QRunnable
{
std::function<void()> m_functionToRun;
public:
FunctionRunnable(std::function<void()> functionToRun) : m_functionToRun(std::move(functionToRun))
{
}
void run() override
{
m_functionToRun();
}
};
#endif
class KSysGuard::CGroupPrivate
{
public:
......@@ -120,7 +135,12 @@ void CGroup::requestPids(QPointer<QObject> context, std::function<void()> callba
QMetaObject::invokeMethod(context, callback);
}
};
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QThreadPool::globalInstance()->start(runnable);
#else
QThreadPool::globalInstance()->start(new FunctionRunnable(std::move(runnable)));
#endif
}
QString CGroupPrivate::unescapeName(const QString &name) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment