Http Version - Initial Commit
This commit is contained in:
commit
026ea97284
1 changed files with 978 additions and 0 deletions
49
requestworker.h
Normal file
49
requestworker.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef REQUESTWORKER_H
|
||||
#define REQUESTWORKER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
#include <QThread>
|
||||
#include <chrono>
|
||||
|
||||
class RequestWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged FINAL)
|
||||
QNetworkAccessManager *manager = nullptr;
|
||||
QTimer *timer = nullptr;
|
||||
QString url;
|
||||
int interval;
|
||||
float prev_distance = 0;
|
||||
int max_height = 0;
|
||||
int min_height = 0;
|
||||
bool stop_timer = false;
|
||||
int reply_number = 0;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> prev_time;
|
||||
public:
|
||||
explicit RequestWorker(QObject *parent = nullptr);
|
||||
|
||||
QString status() const;
|
||||
void setStatus(const QString &newStatus);
|
||||
|
||||
signals:
|
||||
void networkReply(float distance, float rate_of_fill, int expected_to_fill);
|
||||
void statusChanged();
|
||||
|
||||
public slots:
|
||||
void setConfig(QJsonObject config);
|
||||
void start();
|
||||
void stop();
|
||||
private slots:
|
||||
void makeRequest();
|
||||
void requestFinished(QNetworkReply *rep);
|
||||
private:
|
||||
QString m_status;
|
||||
};
|
||||
|
||||
#endif // REQUESTWORKER_H
|
||||
Loading…
Reference in a new issue