From 39dc9e84a5b2b8fa8a62abf370c971898695ad4a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 14 Dec 2014 11:54:38 +0100 Subject: Threaded query processing. --- client/threadboundary.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 client/threadboundary.h (limited to 'client/threadboundary.h') diff --git a/client/threadboundary.h b/client/threadboundary.h new file mode 100644 index 0000000..8847849 --- /dev/null +++ b/client/threadboundary.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace async { + /* + * A helper class to invoke a method in a different thread using the event loop. + * The ThreadBoundary object must live in the thread where the function should be called. + */ + class ThreadBoundary : public QObject { + Q_OBJECT + public: + ThreadBoundary(); + virtual ~ThreadBoundary(); + + //Call in worker thread + void callInMainThread(std::function f) { + QMetaObject::invokeMethod(this, "addValueInMainThread", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(std::function, f)); + } + public slots: + //Get's called in main thread by it's eventloop + void addValueInMainThread(std::function f) { + f(); + } + }; +} -- cgit v1.2.3