Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrestreply.h
Go to the documentation of this file.
1// Copyright (C) 2023 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// Qt-Security score:significant reason:default
4
5#ifndef QRESTREPLY_H
6#define QRESTREPLY_H
7
8#include <QtNetwork/qnetworkreply.h>
9
10#include <QtCore/qpointer.h>
11
12#include <optional>
13#include <utility>
14
15QT_BEGIN_NAMESPACE
16
17class QByteArray;
18class QDebug;
19struct QJsonParseError;
20class QJsonDocument;
21class QString;
22
25{
26public:
29
30 QRestReply(QRestReply &&other) noexcept
32 d(std::exchange(other.d, nullptr))
33 {
34 }
36 void swap(QRestReply &other) noexcept
37 {
40 }
41
43
44 Q_NETWORK_EXPORT std::optional<QJsonDocument> readJson(QJsonParseError *error = nullptr);
45 Q_NETWORK_EXPORT QByteArray readBody();
46 Q_NETWORK_EXPORT QString readText();
47
48 bool isSuccess() const
49 {
50 return !hasError() && isHttpStatusSuccess();
51 }
52 Q_NETWORK_EXPORT int httpStatus() const;
53 Q_NETWORK_EXPORT bool isHttpStatusSuccess() const;
54
55 Q_NETWORK_EXPORT bool hasError() const;
58
59private:
60#ifndef QT_NO_DEBUG_STREAM
62#endif
63 QPointer<QNetworkReply> wrapped;
64 QRestReplyPrivate *d = nullptr;
66};
67
68Q_DECLARE_SHARED(QRestReply)
69
70QT_END_NAMESPACE
71
72#endif // QRESTREPLY_H
QNetworkReply * executeRequest(ReqOpRef requestOperation, const QObject *context, QtPrivate::QSlotObjectBase *rawSlot)
QHash< QNetworkReply *, CallerInfo > activeRequests
QNetworkReply * executeRequest(ReqOpRefJson requestOperation, const QJsonDocument &jsonDoc, const QNetworkRequest &request, const QObject *context, QtPrivate::QSlotObjectBase *rawSlot)
QNetworkAccessManager * qnam
void handleReplyFinished(QNetworkReply *reply)
QNetworkReply * createActiveRequest(QNetworkReply *reply, const QObject *contextObject, QtPrivate::SlotObjUniquePtr slot)
void verifyThreadAffinity(const QObject *contextObject)
The QRestAccessManager is a convenience wrapper for QNetworkAccessManager.
QRestReply is a convenience wrapper for QNetworkReply.
Definition qrestreply.h:25
Q_NETWORK_EXPORT int httpStatus() const
Returns the HTTP status received in the server response.
Q_NETWORK_EXPORT bool isHttpStatusSuccess() const
Returns whether the HTTP status is between 200..299.
QRestReply(QRestReply &&other) noexcept
Move-constructs the reply from other.
Definition qrestreply.h:30
bool isSuccess() const
Returns whether the HTTP status is between 200..299 and no further errors have occurred while receivi...
Definition qrestreply.h:48
Q_NETWORK_EXPORT bool hasError() const
Returns whether an error has occurred.
Q_NETWORK_EXPORT ~QRestReply()
Destroys this QRestReply object.
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
static const QByteArray & PATCH()
#define QREST_METHOD_CUSTOM_WITH_DATA(DATA)
#define QREST_METHOD_NO_DATA(METHOD)
#define QREST_METHOD_WITH_DATA(METHOD, DATA)