QGrpcChannelOptions Class
The QGrpcChannelOptions class offers various options for fine-tuning a gRPC channel. More...
Header: | #include <QGrpcChannelOptions> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Grpc) target_link_libraries(mytarget PRIVATE Qt6::Grpc) |
Since: | Qt 6.6 |
In QML: | GrpcChannelOptions |
Public Functions
QGrpcChannelOptions() | |
QGrpcChannelOptions(const QGrpcChannelOptions &other) | |
QGrpcChannelOptions(QGrpcChannelOptions &&other) | |
~QGrpcChannelOptions() | |
(since 6.10) QGrpcChannelOptions & | addMetadata(QByteArray key, QByteArray value) |
std::optional<std::chrono::milliseconds> | deadlineTimeout() const |
(until 6.13) QHash<QByteArray, QByteArray> | metadata() && |
(until 6.13) const QHash<QByteArray, QByteArray> & | metadata() const & |
(since 6.10) QMultiHash<QByteArray, QByteArray> | metadata(QtGrpc::MultiValue_t) && |
(since 6.10) const QMultiHash<QByteArray, QByteArray> & | metadata(QtGrpc::MultiValue_t) const & |
(since 6.8) QGrpcSerializationFormat | serializationFormat() const |
QGrpcChannelOptions & | setDeadlineTimeout(std::chrono::milliseconds timeout) |
(until 6.13) QGrpcChannelOptions & | setMetadata(QHash<QByteArray, QByteArray> &&metadata) |
(since 6.10) QGrpcChannelOptions & | setMetadata(QMultiHash<QByteArray, QByteArray> &&metadata) |
(until 6.13) QGrpcChannelOptions & | setMetadata(const QHash<QByteArray, QByteArray> &metadata) |
(since 6.10) QGrpcChannelOptions & | setMetadata(const QMultiHash<QByteArray, QByteArray> &metadata) |
(since 6.10) QGrpcChannelOptions & | setMetadata(std::initializer_list<std::pair<QByteArray, QByteArray>> list) |
(since 6.8) QGrpcChannelOptions & | setSerializationFormat(const QGrpcSerializationFormat &format) |
QGrpcChannelOptions & | setSslConfiguration(const QSslConfiguration &sslConfiguration) |
std::optional<QSslConfiguration> | sslConfiguration() const |
(since 6.8) void | swap(QGrpcChannelOptions &other) |
(since 6.8) QVariant | operator QVariant() const |
QGrpcChannelOptions & | operator=(QGrpcChannelOptions &&other) |
QGrpcChannelOptions & | operator=(const QGrpcChannelOptions &other) |
Related Non-Members
(since 6.8) QDebug | operator<<(QDebug debug, const QGrpcChannelOptions &chOpts) |
Detailed Description
QGrpcChannelOptions lets you customize a gRPC™ channel. Some options apply to all remote procedure calls (RPCs) that operate on the associated channel, which is used to communicate with services.
Override options for specific RPCs with QGrpcCallOptions.
QGrpcChannelOptions channelOpts; // Apply common metadata to every RPC channelOpts.setMetadata({ { "header" , "value1" }, { "header" , "value2" }, }); const auto &md = channelOpts.metadata(QtGrpc::MultiValue); qDebug() << "Channel Metadata: " << md; // Apply a 2-second deadline to every RPC channelOpts.setDeadlineTimeout(2s); qDebug() << "Channel timeout: " << channelOpts.deadlineTimeout(); // Configure SSL/TLS configuration channelOpts.setSslConfiguration(QSslConfiguration());
Note: It is up to the channel's implementation to determine the specifics of these options.
Member Function Documentation
[until 6.13]
QHash<QByteArray, QByteArray> QGrpcChannelOptions::metadata() &&
[noexcept, until 6.13]
const QHash<QByteArray, QByteArray> &QGrpcChannelOptions::metadata() const &
This function is scheduled for deprecation in version 6.13.
Use metadata(QtGrpc::MultiValue) instead.
Returns the metadata. If this field is unset, returns empty metadata.
See also metadata(QtGrpc::MultiValue_t) and setMetadata().
[until 6.13]
QGrpcChannelOptions &QGrpcChannelOptions::setMetadata(QHash<QByteArray, QByteArray> &&metadata)
[until 6.13]
QGrpcChannelOptions &QGrpcChannelOptions::setMetadata(const QHash<QByteArray, QByteArray> &metadata)
This function is scheduled for deprecation in version 6.13.
Use the QMultiHash overload instead.
Sets the metadata and returns a reference to the updated object.
When using QGrpcHttp2Channel, the metadata is converted to HTTP/2 headers and added to the gRPC request.
Note: This metadata is included in every RPC made through the channel. Channel metadata is merged with any call-specific metadata when the RPC starts — see QGrpcCallOptions::setMetadata(QMultiHash)
See also metadata().
[since 6.10]
QMultiHash<QByteArray, QByteArray> QGrpcChannelOptions::metadata(QtGrpc::MultiValue_t) &&
[noexcept, since 6.10]
const QMultiHash<QByteArray, QByteArray> &QGrpcChannelOptions::metadata(QtGrpc::MultiValue_t) const &
Returns the metadata. If this field is unset, returns empty metadata. Multiple values per key are supported.
const auto &md = opts.metadata(QtGrpc::MultiValue);
This function was introduced in Qt 6.10.
See also setMetadata.
[since 6.10]
QGrpcChannelOptions &QGrpcChannelOptions::setMetadata(QMultiHash<QByteArray, QByteArray> &&metadata)
[since 6.10]
QGrpcChannelOptions &QGrpcChannelOptions::setMetadata(const QMultiHash<QByteArray, QByteArray> &metadata)
[since 6.10]
QGrpcChannelOptions &QGrpcChannelOptions::setMetadata(std::initializer_list<std::pair<QByteArray, QByteArray>> list)
Sets the metadata and returns a reference to the updated object.
When using QGrpcHttp2Channel, the metadata is converted to HTTP/2 headers and added to the gRPC request. Multiple values per key are supported.
Note: This metadata is included in every RPC made through the channel. Channel metadata is merged with any call-specific metadata when the RPC starts — see QGrpcCallOptions::setMetadata(QMultiHash)
This function was introduced in Qt 6.10.
See also metadata(QtGrpc::MultiValue_t).
QGrpcChannelOptions::QGrpcChannelOptions()
Default-constructs an empty QGrpcChannelOptions.
QGrpcChannelOptions::QGrpcChannelOptions(const QGrpcChannelOptions &other)
Copy-constructs a QGrpcChannelOptions from other.
[noexcept]
QGrpcChannelOptions::QGrpcChannelOptions(QGrpcChannelOptions &&other)
Move-constructs a new QGrpcChannelOptions from other.
Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.
[noexcept]
QGrpcChannelOptions::~QGrpcChannelOptions()
Destroys the QGrpcChannelOptions.
[since 6.10]
QGrpcChannelOptions &QGrpcChannelOptions::addMetadata(QByteArray key, QByteArray value)
Adds key and value to the metadata if the exact pair is not already contained. The same key may appear multiple times with different values.
Note: This metadata is included in every RPC made through the channel. Channel metadata is merged with any call-specific metadata when the RPC starts — see QGrpcCallOptions::addMetadata()
This function was introduced in Qt 6.10.
See also metadata() and setMetadata().
[noexcept]
std::optional<std::chrono::milliseconds> QGrpcChannelOptions::deadlineTimeout() const
Returns the timeout duration that is used to calculate the deadline for the channel.
If this field is unset, returns an empty std::optional
.
See also setDeadlineTimeout().
[since 6.8]
QGrpcSerializationFormat QGrpcChannelOptions::serializationFormat() const
Returns the serialization format used by the channel.
If this field is unset, returns a Default constructed serialization format.
This function was introduced in Qt 6.8.
See also setSerializationFormat().
QGrpcChannelOptions &QGrpcChannelOptions::setDeadlineTimeout(std::chrono::milliseconds timeout)
Sets the timeout and returns a reference to the updated object.
A deadline sets the limit for how long a client is willing to wait for a response from a server. The actual deadline is computed by adding the timeout to the start time of the RPC.
The deadline applies to the entire lifetime of an RPC, which includes receiving the final QGrpcStatus for a previously started call and can thus be unwanted for (long-lived) streams.
Note: Setting this field applies to all RPCs that operate on the channel, except those overriden by QGrpcCallOptions::setDeadlineTimeout()
See also deadlineTimeout().
[since 6.8]
QGrpcChannelOptions &QGrpcChannelOptions::setSerializationFormat(const QGrpcSerializationFormat &format)
Sets the serialization format for the channel and returns a reference to the updated object.
This function was introduced in Qt 6.8.
See also serializationFormat().
QGrpcChannelOptions &QGrpcChannelOptions::setSslConfiguration(const QSslConfiguration &sslConfiguration)
Sets the sslConfiguration for the channel and returns a reference to the updated object.
See also sslConfiguration().
std::optional<QSslConfiguration> QGrpcChannelOptions::sslConfiguration() const
Returns the SSL configuration for the channel.
If this field is unset, returns an empty std::optional
.
See also setSslConfiguration().
[noexcept, since 6.8]
void QGrpcChannelOptions::swap(QGrpcChannelOptions &other)
Swaps other with this object. This operation is very fast and never fails.
This function was introduced in Qt 6.8.
[since 6.8]
QVariant QGrpcChannelOptions::operator QVariant() const
Constructs a new QVariant from this object.
This function was introduced in Qt 6.8.
[noexcept]
QGrpcChannelOptions &QGrpcChannelOptions::operator=(QGrpcChannelOptions &&other)
Move-assigns other to this QGrpcChannelOptions and returns a reference to the updated object.
Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.
QGrpcChannelOptions &QGrpcChannelOptions::operator=(const QGrpcChannelOptions &other)
Assigns other to this QGrpcChannelOptions and returns a reference to the updated object.
Related Non-Members
[since 6.8]
QDebug operator<<(QDebug debug, const QGrpcChannelOptions &chOpts)
Writes chOpts to the specified stream debug.
This function was introduced in Qt 6.8.
© 2025 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.