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
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
4#ifndef QRESTREPLY_H
5#define QRESTREPLY_H
6
7#include <QtNetwork/qnetworkreply.h>
8
9#include <QtCore/qpointer.h>
10
11#include <optional>
12#include <utility>
13
15
16class QByteArray;
17class QDebug;
18struct QJsonParseError;
19class QJsonDocument;
20class QString;
21
24{
25public:
26 Q_NETWORK_EXPORT explicit QRestReply(QNetworkReply *reply);
27 Q_NETWORK_EXPORT ~QRestReply();
28
30 : wrapped(std::move(other.wrapped)),
31 d(std::exchange(other.d, nullptr))
32 {
33 }
34 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRestReply)
36 {
37 wrapped.swap(other.wrapped);
39 }
40
41 Q_NETWORK_EXPORT QNetworkReply *networkReply() const;
42
43 Q_NETWORK_EXPORT std::optional<QJsonDocument> readJson(QJsonParseError *error = nullptr);
44 Q_NETWORK_EXPORT QByteArray readBody();
45 Q_NETWORK_EXPORT QString readText();
46
47 bool isSuccess() const
48 {
49 return !hasError() && isHttpStatusSuccess();
50 }
51 Q_NETWORK_EXPORT int httpStatus() const;
52 Q_NETWORK_EXPORT bool isHttpStatusSuccess() const;
53
54 Q_NETWORK_EXPORT bool hasError() const;
55 Q_NETWORK_EXPORT QNetworkReply::NetworkError error() const;
56 Q_NETWORK_EXPORT QString errorString() const;
57
58private:
59#ifndef QT_NO_DEBUG_STREAM
60 friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QRestReply &reply);
61#endif
62 QPointer<QNetworkReply> wrapped;
63 QRestReplyPrivate *d = nullptr;
64 Q_DISABLE_COPY(QRestReply)
65};
66
67Q_DECLARE_SHARED(QRestReply)
68
70
71#endif // QRESTREPLY_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore\reentrant
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
NetworkError
Indicates all possible error conditions found during the processing of the request.
QRestReply is a convenience wrapper for QNetworkReply.
Definition qrestreply.h:24
QRestReply(QRestReply &&other) noexcept
Move-constructs the reply from other.
Definition qrestreply.h:29
bool isSuccess() const
Returns whether the HTTP status is between 200..299 and no further errors have occurred while receivi...
Definition qrestreply.h:47
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:29
#define QT_TECH_PREVIEW_API
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QSharedPointer< T > other(t)
[5]
this swap(other)
QNetworkReply * reply
\inmodule QtCore\reentrant