QGrpcCallOptions Class

The QGrpcCallOptions class offers various options for fine-tuning individual RPCs. More...

Header: #include <QGrpcCallOptions>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Since: Qt 6.6
In QML: GrpcCallOptions

Public Functions

QGrpcCallOptions()
QGrpcCallOptions(const QGrpcCallOptions &other)
QGrpcCallOptions(QGrpcCallOptions &&other)
~QGrpcCallOptions()
(since 6.10) QGrpcCallOptions &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::MultiValueTag) &&
(since 6.10) const QMultiHash<QByteArray, QByteArray> &metadata(QtGrpc::MultiValueTag) const &
QGrpcCallOptions &setDeadlineTimeout(std::chrono::milliseconds timeout)
(until 6.13) QGrpcCallOptions &setMetadata(QHash<QByteArray, QByteArray> &&metadata)
(since 6.10) QGrpcCallOptions &setMetadata(QMultiHash<QByteArray, QByteArray> &&metadata)
(until 6.13) QGrpcCallOptions &setMetadata(const QHash<QByteArray, QByteArray> &metadata)
(since 6.10) QGrpcCallOptions &setMetadata(const QMultiHash<QByteArray, QByteArray> &metadata)
(since 6.10) QGrpcCallOptions &setMetadata(std::initializer_list<std::pair<QByteArray, QByteArray>> metadata)
(since 6.8) void swap(QGrpcCallOptions &other)
(since 6.8) QVariant operator QVariant() const
QGrpcCallOptions &operator=(QGrpcCallOptions &&other)
QGrpcCallOptions &operator=(const QGrpcCallOptions &other)
(since 6.8) QDebug operator<<(QDebug debug, const QGrpcCallOptions &callOpts)

Detailed Description

QGrpcCallOptions lets you customize individual remote procedure calls (RPCs). The generated client interface provides access points to pass the QGrpcCallOptions. These options supersede the ones set via QGrpcChannelOptions.

To configure the default options shared by RPCs, use QGrpcChannelOptions.

QGrpcCallOptions callOpts;
// Set the metadata for an individial RPC
callOpts.setMetadata({
    { "header" , "value1" },
    { "header" , "value2" },
});
const auto &md = callOpts.metadata(QtGrpc::MultiValue);
qDebug() << "Call Metadata: " << md;

// Set a 2-second deadline for an individial RPC
callOpts.setDeadlineTimeout(2s);
qDebug() << "Call timeout: " << callOpts.deadlineTimeout();

Member Function Documentation

[until 6.13] QHash<QByteArray, QByteArray> QGrpcCallOptions::metadata() &&

[noexcept, until 6.13] const QHash<QByteArray, QByteArray> &QGrpcCallOptions::metadata() const &

This function is scheduled for deprecation in version 6.13.

Use the QMultiHash overload instead.

Returns the metadata. If this field is unset, returns empty metadata.

See also setMetadata().

[until 6.13] QGrpcCallOptions &QGrpcCallOptions::setMetadata(QHash<QByteArray, QByteArray> &&metadata)

[until 6.13] QGrpcCallOptions &QGrpcCallOptions::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: Call metadata is merged with any channel-level metadata when the RPC starts — see QGrpcChannelOptions::setMetadata(QMultiHash).

See also metadata().

[since 6.10] QMultiHash<QByteArray, QByteArray> QGrpcCallOptions::metadata(QtGrpc::MultiValueTag) &&

[noexcept, since 6.10] const QMultiHash<QByteArray, QByteArray> &QGrpcCallOptions::metadata(QtGrpc::MultiValueTag) 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] QGrpcCallOptions &QGrpcCallOptions::setMetadata(QMultiHash<QByteArray, QByteArray> &&metadata)

[since 6.10] QGrpcCallOptions &QGrpcCallOptions::setMetadata(const QMultiHash<QByteArray, QByteArray> &metadata)

[since 6.10] QGrpcCallOptions &QGrpcCallOptions::setMetadata(std::initializer_list<std::pair<QByteArray, QByteArray>> metadata)

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: Call metadata is merged with any channel-level metadata when the RPC starts — see QGrpcChannelOptions::setMetadata(QMultiHash).

This function was introduced in Qt 6.10.

See also metadata(QtGrpc::MultiValueTag).

QGrpcCallOptions::QGrpcCallOptions()

Default-constructs an empty QGrpcCallOptions.

QGrpcCallOptions::QGrpcCallOptions(const QGrpcCallOptions &other)

Copy-constructs a QGrpcCallOptions from other.

[noexcept] QGrpcCallOptions::QGrpcCallOptions(QGrpcCallOptions &&other)

Move-constructs a new QGrpcCallOptions 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] QGrpcCallOptions::~QGrpcCallOptions()

Destroys the QGrpcCallOptions.

[since 6.10] QGrpcCallOptions &QGrpcCallOptions::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: Call metadata is merged with any channel-level metadata when the RPC starts — see QGrpcChannelOptions::addMetadata()

This function was introduced in Qt 6.10.

See also metadata() and setMetadata().

[noexcept] std::optional<std::chrono::milliseconds> QGrpcCallOptions::deadlineTimeout() const

Returns the timeout duration that is used to calculate the deadline for RPCs.

If this field is unset, returns an empty std::optional.

See also setDeadlineTimeout().

QGrpcCallOptions &QGrpcCallOptions::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 overrides the corresponding channel options field — see QGrpcChannelOptions::setDeadlineTimeout()

See also deadlineTimeout().

[noexcept, since 6.8] void QGrpcCallOptions::swap(QGrpcCallOptions &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 QGrpcCallOptions::operator QVariant() const

Constructs a new QVariant from this object.

This function was introduced in Qt 6.8.

[noexcept] QGrpcCallOptions &QGrpcCallOptions::operator=(QGrpcCallOptions &&other)

Move-assigns other to this QGrpcCallOptions 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.

QGrpcCallOptions &QGrpcCallOptions::operator=(const QGrpcCallOptions &other)

Assigns other to this QGrpcCallOptions and returns a reference to the updated object.

Related Non-Members

[since 6.8] QDebug operator<<(QDebug debug, const QGrpcCallOptions &callOpts)

Writes callOpts 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.