Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qnetworkreplydataimpl.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "private/qdataurl_p.h"
6#include <QtCore/QCoreApplication>
7#include <QtCore/QMetaObject>
8
10
15
19
23
26{
28 setRequest(req);
29 setUrl(req.url());
30 setOperation(op);
31 setFinished(true);
33
34 QUrl url = req.url();
36 QByteArray payload;
37 if (qDecodeDataUrl(url, mimeType, payload)) {
38 qint64 size = payload.size();
39 auto h = headers();
42 setHeaders(std::move(h));
43
44 QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
45
46 d->decodedData.setData(payload);
47 d->decodedData.open(QIODevice::ReadOnly);
48
49 QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
53 } else {
54 // something wrong with this URI
55 const QString msg = QCoreApplication::translate("QNetworkAccessDataBackend",
56 "Invalid URI: %1").arg(url.toString());
61 }
62}
63
68
73
75{
76 Q_D(const QNetworkReplyDataImpl);
77 return QNetworkReply::bytesAvailable() + d->decodedData.bytesAvailable();
78}
79
81{
82 return true;
83}
84
86{
87 Q_D(const QNetworkReplyDataImpl);
88 return d->decodedData.size();
89}
90
95{
97
98 // TODO idea:
99 // Instead of decoding the whole data into new memory, we could decode on demand.
100 // Note that this might be tricky to do.
101
102 return d->decodedData.read(data, maxlen);
103}
104
105
107
108#include "moc_qnetworkreplydataimpl_p.cpp"
109
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Operation
Indicates the operation this reply is processing.
virtual void close() override
Closes this device for reading.
virtual void abort() override
Aborts the operation immediately and close down any network connections still open.
QNetworkReplyDataImpl(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op)
virtual qint64 readData(char *data, qint64 maxlen) override
qint64 size() const override
For open random-access devices, this function returns the size of the device.
virtual qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
virtual bool isSequential() const override
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void setError(NetworkError errorCode, const QString &errorString)
Sets the error condition to be errorCode.
virtual void close() override
Closes this device for reading.
QHttpHeaders headers() const
void setOperation(QNetworkAccessManager::Operation operation)
Sets the associated operation for this object to be operation.
void setUrl(const QUrl &url)
Sets the URL being processed to be url.
void setHeaders(const QHttpHeaders &newHeaders)
void setRequest(const QNetworkRequest &request)
Sets the associated request for this object to be request.
NetworkError
Indicates all possible error conditions found during the processing of the request.
void setFinished(bool)
QUrl url() const
Returns the URL of the content downloaded or uploaded.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QUrl url() const
Returns the URL this network request is referring to.
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2831
Combined button and popup list for selecting options.
@ QueuedConnection
Q_CORE_EXPORT bool qDecodeDataUrl(const QUrl &uri, QString &mimeType, QByteArray &payload)
Definition qdataurl.cpp:18
const char * mimeType
#define Q_ARG(Type, data)
Definition qobjectdefs.h:63
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
long long qint64
Definition qtypes.h:60
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...