QtPdCom  1.3.3
QtPdCom::VariableWatcher Class Reference

Convenience class for processing the result of Process::findQt() More...

#include <FutureWatchers.h>

Inheritance diagram for QtPdCom::VariableWatcher:
Inheritance graph
[legend]
Collaboration diagram for QtPdCom::VariableWatcher:
Collaboration graph
[legend]

Detailed Description

Convenience class for processing the result of Process::findQt()

Let's say you have a Widget which needs to process a PdCom::Variable instance.

class MyWidget : public QObject
{
Q_OBJECT
public:
MyWidget(QObject *parent) : QObject(parent) {}
void setVariable(QtPdCom::Process& proc, QString path)
{
const auto watcher = new QtPdCom::VariableWatcher(this);
// this will be fired when the result has arrived
connect(watcher, &QtPdCom::VariableWatcher::finished,
this, &MyWidget::onVariableFound);
// delete watcher if Process is resetted in the meantime
connect(watcher, &QtPdCom::VarableWatcher::cancelled,
watcher, &QObject::deleteLater);
// start watching
watcher->setFuture(proc.find(path));
}
private slots:
void onVariableFound()
{
const auto watcher =
qobject_cast<QtPdCom::FindVariableWatcher*>(QObject::sender()); if
(!watcher) return;
// fetch result from watcher
const PdCom::Variable result = watcher->result();
watcher->deleteLater();
// handle result
}
};

The documentation for this class was generated from the following file: