1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-16 22:28:57 +00:00
CLK/OSBindings/Qt/functionthread.h
Thomas Harte 405e9e7c68 Shunts audio into its own QThread.
For the record, this was the first means I found of attempting that which actually seemed to work. A plain QThread, with something `connect`ed to its `started` signal didn't seem to work (perhaps `connect` is smart at thread confinement?), `moveToThread` didn't work on the audio output after the fact, etc.
2020-06-10 22:14:54 -04:00

32 lines
644 B
C++

#ifndef FUNCTIONTHREAD_H
#define FUNCTIONTHREAD_H
#include <QThread>
/*!
* \brief The LambdaThread class
*
* Provides a QThread which performs a supplied lambda before kicking off its event loop.
*
* Disclaimer: this might be a crutch that reveals a misunderstanding of the Qt
* threading infrastructure. We'll see.
*/
class FunctionThread: public QThread {
public:
FunctionThread() : QThread() {}
void setFunction(const std::function<void(void)> &function) {
this->function = function;
}
void run() override {
function();
exec();
}
private:
std::function<void(void)> function;
};
#endif // FUNCTIONTHREAD_H