mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-29 02:22:09 +08:00
RequestRepeater remove memory leak through payloads argument
old-commit-hash: 7bc0b27ae540c941914f63e8fc5f81f8c515eb1b
This commit is contained in:
@@ -76,14 +76,14 @@ QString CommaApi::create_jwt() {
|
||||
return create_jwt(*(new QVector<QPair<QString, QJsonValue>>()));
|
||||
}
|
||||
|
||||
RequestRepeater::RequestRepeater(QWidget* parent, QString requestURL, int period_seconds, const QString &cache_key, QVector<QPair<QString, QJsonValue>> payloads, bool disableWithScreen)
|
||||
RequestRepeater::RequestRepeater(QWidget* parent, QString requestURL, int period_seconds, const QString &cache_key, bool disableWithScreen)
|
||||
: disableWithScreen(disableWithScreen), cache_key(cache_key), QObject(parent) {
|
||||
networkAccessManager = new QNetworkAccessManager(this);
|
||||
|
||||
reply = NULL;
|
||||
|
||||
QTimer* timer = new QTimer(this);
|
||||
QObject::connect(timer, &QTimer::timeout, [=](){sendRequest(requestURL, payloads);});
|
||||
QObject::connect(timer, &QTimer::timeout, [=](){sendRequest(requestURL);});
|
||||
timer->start(period_seconds * 1000);
|
||||
|
||||
networkTimer = new QTimer(this);
|
||||
@@ -98,13 +98,13 @@ RequestRepeater::RequestRepeater(QWidget* parent, QString requestURL, int period
|
||||
}
|
||||
}
|
||||
|
||||
void RequestRepeater::sendRequest(QString requestURL, QVector<QPair<QString, QJsonValue>> payloads){
|
||||
void RequestRepeater::sendRequest(QString requestURL){
|
||||
if (GLWindow::ui_state.scene.started || !active || reply != NULL ||
|
||||
(!GLWindow::ui_state.awake && disableWithScreen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString token = CommaApi::create_jwt(payloads);
|
||||
QString token = CommaApi::create_jwt({});
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(requestURL));
|
||||
request.setRawHeader(QByteArray("Authorization"), ("JWT " + token).toUtf8());
|
||||
|
||||
@@ -33,7 +33,7 @@ class RequestRepeater : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RequestRepeater(QWidget* parent, QString requestURL, int period = 10, const QString &cache_key = "", QVector<QPair<QString, QJsonValue>> payloads = *(new QVector<QPair<QString, QJsonValue>>()), bool disableWithScreen = true);
|
||||
explicit RequestRepeater(QWidget* parent, QString requestURL, int period = 10, const QString &cache_key = "", bool disableWithScreen = true);
|
||||
bool active = true;
|
||||
|
||||
private:
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
QNetworkAccessManager* networkAccessManager;
|
||||
QTimer* networkTimer;
|
||||
QString cache_key;
|
||||
void sendRequest(QString requestURL, QVector<QPair<QString, QJsonValue>> payloads);
|
||||
void sendRequest(QString requestURL);
|
||||
|
||||
private slots:
|
||||
void requestTimeout();
|
||||
|
||||
Reference in New Issue
Block a user