Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
trinity/include/requestsender.h

36 lines
714 B
C
Raw Normal View History

2021-07-21 16:08:15 -04:00
#pragma once
#include <QNetworkReply>
#include <QNetworkRequest>
2022-08-15 21:53:56 -04:00
#include <QObject>
#include <functional>
2021-07-21 16:08:15 -04:00
2022-08-15 21:53:56 -04:00
class RequestSender : public QObject {
2021-07-21 16:08:15 -04:00
Q_OBJECT
public:
RequestSender(QObject* parent = nullptr) : QObject(parent) {}
RequestSender(const RequestSender& other) {
fn = other.fn;
}
~RequestSender() {
QObject::disconnect(this);
}
std::function<void(QNetworkReply*)> fn;
void finished(QNetworkReply* reply) {
2022-08-15 21:53:56 -04:00
if (reply->request().originatingObject() == this) {
// qDebug() << reply->errorString();
2021-07-21 16:08:15 -04:00
fn(reply);
deleteLater();
reply->deleteLater();
}
}
};
Q_DECLARE_METATYPE(RequestSender)