QGrpcOperation Class

The QGrpcOperation class provides common operations to handle the gRPC communication from the client side. 更多...

頭: #include <QGrpcOperation>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Since: Qt 6.5
繼承: QObject
繼承者:

QGrpcBidiStream , QGrpcCallReply , QGrpcClientStream ,和 QGrpcServerStream

公共函數

virtual ~QGrpcOperation () override
bool isFinished () const
const QHash<QByteArray, QByteArray> & metadata () const &
QLatin1StringView method () const
std::optional<T> read () const
(從 6.8 起) bool read (QProtobufMessage * message ) const

公共槽

void cancel ()

信號

void finished (const QGrpcStatus & status )

詳細描述

QGrpcOperation serves as the base class for the four gRPC method types: QGrpcCallReply (unary calls), QGrpcServerStream (server streaming), QGrpcClientStream (client streaming), and QGrpcBidiStream (bidirectional streaming). It provides a common interface for interacting with these remote procedure calls (RPCs).

Each QGrpcOperation corresponds to a specific RPC requested through the generated client interface.

For a high-level overview, refer to the Qt GRPC Client Guide .

成員函數文檔編製

[override virtual noexcept] QGrpcOperation:: ~QGrpcOperation ()

銷毀 QGrpcOperation .

[slot] void QGrpcOperation:: cancel ()

Tries to cancel the RPC immediately. Successful cancellation cannot be guaranteed. Emits the finished signal with a Cancelled status code.

另請參閱 QGrpcOperationContext::cancelRequested .

[signal] void QGrpcOperation:: finished (const QGrpcStatus & status )

This signal is emitted when a previously started RPC has finished. The status provides additional information about the outcome of the RPC.

After this signal is received, no further write or read operations should be performed on the operation object. At this point, it is safe to reuse or destroy the RPC object.

注意: This signal is emitted only once, and in most cases, you will want to disconnect right after receiving it to avoid issues, such as lambda captures not being destroyed after receiving the signal. An easy way to achieve this is by using the SingleShotConnection connection type. See Single Shot RPCs 進一步瞭解細節。

[noexcept] bool QGrpcOperation:: isFinished () const

Returns true if this operation has finished, meaning that no more operations can happen on the corresponding RPC, otherwise returns false.

[noexcept] const QHash < QByteArray , QByteArray > &QGrpcOperation:: metadata () const &

Returns the server metadata received from the channel.

注意: QGrpcHttp2Channel transports metadata as HTTP/2 headers. are case-insensitive ASCII strings. You must avoid using the internal prefixes: : (pseudo-header), grpc- ,或 qtgrpc- . may be either ASCII strings or binary data. For more information, see RFC 7540, Section 8.1.2 .

[noexcept] QLatin1StringView QGrpcOperation:: method () const

Returns the method name associated with this RPC operation.

template <typename T, QtProtobuf::if_protobuf_message<T> = true> std::optional < T > QGrpcOperation:: read () const

Reads a message from a raw byte array stored within this operation object.

Returns an optional deserialized message. On failure, std::nullopt 被返迴。

注意: This function only participates in overload resolution if T 是子類化的 QProtobufMessage .

另請參閱 read (QProtobufMessage *).

[since 6.8] bool QGrpcOperation:: read ( QProtobufMessage * message ) const

Reads a message from a raw byte array stored within this operation object.

The function writes the deserialized value to the message 指針。

If the deserialization is successful, this function returns true . Otherwise, it returns false .

該函數在 Qt 6.8 引入。

另請參閱 read ().