qt: add ReadableObsevable

This commit is contained in:
Jussi Kuokkanen 2019-11-17 15:09:30 +02:00
parent 587475e81b
commit 05b437e454
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#include "ReadableObservable.h"
ReadableObservable::ReadableObservable(ReadableData *data, QObject *parent) : QObject(parent) {
m_readableData = data;
m_emitTimer = new QTimer;
}
void ReadableObservable::setInterval(std::chrono::milliseconds msecs) {
m_emitTimer->start(msecs);
connect(m_emitTimer, &QTimer::timeout, [=]() {
emit valueUpdated(m_latestValue);
});
}

View File

@ -0,0 +1,20 @@
#pragma once
#include <QObject>
#include <QTimer>
#include "ReadableData.h"
class ReadableObservable : public QObject {
public:
ReadableObservable(ReadableData *data, QObject *parent = nullptr);
void setInterval(std::chrono::milliseconds msecs); // Set the emission interval
signals:
void valueUpdated(tc_readable_result_t value);
private:
Q_OBJECT
ReadableData *m_readableData;
QTimer *m_emitTimer;
tc_readable_result_t m_latestValue;
};