QGrpcClientBase Class

The QGrpcClientBase class is bridge between gRPC clients and channels. More...

Header: #include <QGrpcClientBase>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Since: Qt 6.5
Inherits: QObject
Status: Technical Preview

Public Functions

void attachChannel(std::shared_ptr<QAbstractGrpcChannel> channel)
(since 6.7) std::shared_ptr<QAbstractGrpcChannel> channel() const

Signals

(since 6.7) void channelChanged()
void errorOccurred(const QGrpcStatus &status)

Protected Functions

std::shared_ptr<StreamType> startStream(QLatin1StringView method, const QProtobufMessage &arg, const QGrpcCallOptions &options)

Detailed Description

QGrpcClientBase provides a set of functions for client classes generated out of protobuf services. QGrpcClientBase enforces thread safety for startStream() and call() methods of generated clients. The methods QGrpcClientBase::call() and QGrpcClientBase::startStream() should only be called by the generated client classes.

Member Function Documentation

void QGrpcClientBase::attachChannel(std::shared_ptr<QAbstractGrpcChannel> channel)

Attaches channel to client as transport layer for gRPC.

Parameters and return values will be serialized to the channel in a format it supports.

Note: Warning: Qt GRPC doesn't guarantee thread safety on the channel level. You have to invoke the channel-related functions on the same thread as QGrpcClientBase.

Note: Setter function for property channel.

[noexcept, since 6.7] std::shared_ptr<QAbstractGrpcChannel> QGrpcClientBase::channel() const

Returns the channel attached to this client.

Note: Getter function for property channel.

This function was introduced in Qt 6.7.

[signal, since 6.7] void QGrpcClientBase::channelChanged()

Indicates that a new channel is attached to the client.

Note: Notifier signal for property channel.

This function was introduced in Qt 6.7.

[signal] void QGrpcClientBase::errorOccurred(const QGrpcStatus &status)

Indicates that an error occurred during serialization.

This signal is emitted when an error with status occurs in the channel or during serialization.

See also QGrpcOperation::errorOccurred.

[protected] template <typename StreamType, QGrpcClientBase::if_qtgrpc_stream<StreamType> = true> std::shared_ptr<StreamType> QGrpcClientBase::startStream(QLatin1StringView method, const QProtobufMessage &arg, const QGrpcCallOptions &options)

Starts the stream method of the StreamType type with the message argument arg to the attached channel.

Uses options argument to set additional parameter in the stream communication.

The implementation is only available for StreamType: QGrpcServerStream, QGrpcClientStream, and QGrpcBidirStream.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.