QtPdCom  1.5.2
FutureWatchers.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 2009 - 2022 Bjarne von Horn <vh@igh.de>
4 *
5 * This file is part of the QtPdCom library.
6 *
7 * The QtPdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The QtPdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22
23#ifndef QTPDCOM_FUTUREWATCHERS_H
24#define QTPDCOM_FUTUREWATCHERS_H
25
26#include <QFutureWatcher>
27#include <pdcom5/Variable.h>
28#include "VariableList.h"
29#include "Export.h"
30#include "FutureWatchersDetails.h"
31
32
33namespace QtPdCom {
34
82class QTPDCOM_PUBLIC VariableWatcher: public QFutureWatcher<PdCom::Variable>
83{
84 Q_OBJECT
85
86 public:
87 using QFutureWatcher<PdCom::Variable>::QFutureWatcher;
88};
89
90class QTPDCOM_PUBLIC ListWatcher: public QFutureWatcher<VariableList>
91{
92 Q_OBJECT
93
94 public:
95 using QFutureWatcher<VariableList>::QFutureWatcher;
96};
97
98
99template< class Result,class Object, class Callback>
100inline QFutureWatcher<Result>& createWatcher(Object *obj, Callback &&callback)
101{
102 const auto watcher = new QFutureWatcher<Result>(obj);
103 QObject::connect(
104 watcher,
105 &QFutureWatcherBase::finished,
106 obj,
107 [callback, watcher, obj]() {
108 details::invoke<Result, Object>::call(callback, *obj, watcher);
109 watcher->deleteLater();
110 });
111 QObject::connect(
112 watcher,
113 &QFutureWatcherBase::canceled,
114 watcher,
115 &QObject::deleteLater);
116 return *watcher;
117}
118
119
120} // namespace QtPdCom
121
122#endif // QTPDCOM_FUTUREWATCHERS_H
#define QTPDCOM_PUBLIC
Definition Export.h:30
Definition FutureWatchers.h:91
Convenience class for processing the result of Process::findQt().
Definition FutureWatchers.h:83
Definition BroadcastModel.h:32
QFutureWatcher< Result > & createWatcher(Object *obj, Callback &&callback)
Definition FutureWatchers.h:100
Definition VariableList.h:31