diff options
author | Juha Vuolle <juha.vuolle@qt.io> | 2023-07-06 11:59:04 +0300 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@qt.io> | 2023-12-08 15:53:33 +0200 |
commit | e9f703ed3b5ff8a9987c6c4e3b658b41244919e3 (patch) | |
tree | d8b13ce8b14be2cc0e60f1f0e3ffbaf8b50ccd00 /src/network/access | |
parent | e560adef213301318dcc13d4db155624846e0420 (diff) |
Add signals and methods for QRestReply download progress
These include:
- readyRead(), signal for indicating new data availability
- bytesAvailable(), function for checking available data amount
- downloadProgress(), signal for monitoring download progress
Task-number: QTBUG-114717
Change-Id: Id6c49530d7857f5c76bd111eba84525137294ea7
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qrestreply.cpp | 48 | ||||
-rw-r--r-- | src/network/access/qrestreply.h | 3 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/network/access/qrestreply.cpp b/src/network/access/qrestreply.cpp index efff394f83..7770737759 100644 --- a/src/network/access/qrestreply.cpp +++ b/src/network/access/qrestreply.cpp @@ -34,6 +34,33 @@ Q_DECLARE_LOGGING_CATEGORY(lcQrest) */ /*! + \fn void QRestReply::readyRead(QRestReply *reply) + + This signal is emitted when \a reply has received new data. + + \sa body(), bytesAvailable(), isFinished() +*/ + +/*! + \fn void QRestReply::downloadProgress(qint64 bytesReceived, + qint64 bytesTotal, + QRestReply* reply) + + This signal is emitted to indicate the progress of the download part of + this network \a reply. + + The \a bytesReceived parameter indicates the number of bytes received, + while \a bytesTotal indicates the total number of bytes expected to be + downloaded. If the number of bytes to be downloaded is not known, for + instance due to a missing \c Content-Length header, \a bytesTotal + will be -1. + + See \l QNetworkReply::downloadProgress() documentation for more details. + + \sa bytesAvailable(), readyRead() +*/ + +/*! \fn void QRestReply::finished(QRestReply *reply) This signal is emitted when \a reply has finished processing. This @@ -63,6 +90,14 @@ QRestReply::QRestReply(QNetworkReply *reply, QObject *parent) d->networkReply = reply; // Reparent so that destruction of QRestReply destroys QNetworkReply reply->setParent(this); + + QObject::connect(reply, &QNetworkReply::readyRead, this, [this] { + emit readyRead(this); + }); + QObject::connect(reply, &QNetworkReply::downloadProgress, this, + [this](qint64 bytesReceived, qint64 bytesTotal) { + emit downloadProgress(bytesReceived, bytesTotal, this); + }); } /*! @@ -155,7 +190,7 @@ std::optional<QJsonArray> QRestReply::jsonArray() calls to get response data will return empty until further data has been received. - \sa json(), text() + \sa json(), text(), bytesAvailable(), readyRead() */ QByteArray QRestReply::body() { @@ -294,6 +329,17 @@ bool QRestReply::isFinished() const return d->networkReply->isFinished(); } +/*! + Returns the number of bytes available. + + \sa body +*/ +qint64 QRestReply::bytesAvailable() const +{ + Q_D(const QRestReply); + return d->networkReply->bytesAvailable(); +} + QRestReplyPrivate::QRestReplyPrivate() = default; diff --git a/src/network/access/qrestreply.h b/src/network/access/qrestreply.h index 6e35b45003..91e8d17cc3 100644 --- a/src/network/access/qrestreply.h +++ b/src/network/access/qrestreply.h @@ -35,6 +35,7 @@ public: QString errorString() const; bool isFinished() const; + qint64 bytesAvailable() const; public Q_SLOTS: void abort(); @@ -42,6 +43,8 @@ public Q_SLOTS: Q_SIGNALS: void finished(QRestReply *reply); void errorOccurred(QRestReply *reply); + void readyRead(QRestReply *reply); + void downloadProgress(qint64 bytesReceived, qint64 bytesTotal, QRestReply *reply); private: friend class QRestAccessManagerPrivate; |