summaryrefslogtreecommitdiffstats
path: root/client/threadboundary.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-14 11:54:38 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-14 19:14:42 +0100
commit39dc9e84a5b2b8fa8a62abf370c971898695ad4a (patch)
tree80c6880b0002d94b06cc344479df20b95346233a /client/threadboundary.h
parent4dceb1b07227445b88a09cc1b88bfc5878a322bb (diff)
downloadsink-39dc9e84a5b2b8fa8a62abf370c971898695ad4a.tar.gz
sink-39dc9e84a5b2b8fa8a62abf370c971898695ad4a.zip
Threaded query processing.
Diffstat (limited to 'client/threadboundary.h')
-rw-r--r--client/threadboundary.h27
1 files changed, 27 insertions, 0 deletions
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 @@
1#pragma once
2
3#include <QObject>
4#include <functional>
5
6namespace async {
7 /*
8 * A helper class to invoke a method in a different thread using the event loop.
9 * The ThreadBoundary object must live in the thread where the function should be called.
10 */
11 class ThreadBoundary : public QObject {
12 Q_OBJECT
13 public:
14 ThreadBoundary();
15 virtual ~ThreadBoundary();
16
17 //Call in worker thread
18 void callInMainThread(std::function<void()> f) {
19 QMetaObject::invokeMethod(this, "addValueInMainThread", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(std::function<void()>, f));
20 }
21 public slots:
22 //Get's called in main thread by it's eventloop
23 void addValueInMainThread(std::function<void()> f) {
24 f();
25 }
26 };
27}