QGrpcCallOptions Class | Qt GRPC | Qt 6.11.0
Description: The QGrpcCallOptions class offers various options for fine-tuning individual RPCs.

- Qt 6.11
- Qt GRPC
- C++ Classes
- QGrpcCallOptions
- Qt 6.11.0 Reference Documentation

# 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

- List of all members, including inherited members

## Public Functions

| QGrpcCallOptions()
| QGrpcCallOptions(const QGrpcCallOptions &other)
| QGrpcCallOptions(QGrpcCallOptions &&other)
| ~QGrpcCallOptions()
`(since 6.10)` QGrpcCallOptions & | addMetadata(QByteArrayView key, QByteArrayView value)
std::optional<std::chrono::milliseconds> | deadlineTimeout() const
`(since 6.11)` std::optional<bool> | filterServerMetadata() 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 &
QGrpcCallOptions & | setDeadlineTimeout(std::chrono::milliseconds timeout)
`(since 6.11)` QGrpcCallOptions & | setFilterServerMetadata(bool value)
`(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)

## Related Non-Members

`(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::MultiValue_t) &&

### `[noexcept, since 6.10]` const QMultiHash<QByteArray, QByteArray> &QGrpcCallOptions::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]` 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::MultiValue_t).

### 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(QByteArrayView key, QByteArrayView 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().

### `[noexcept, since 6.11]` std::optional<bool> QGrpcCallOptions::filterServerMetadata() const

Returns `true` if protocol-related server metadata is excluded from the result. Returns `false` to include all metadata received from the server.

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

This function was introduced in Qt 6.11.

See also setFilterServerMetadata() and QGrpcChannelOptions::filterServerMetadata().

### 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().

### `[since 6.11]` QGrpcCallOptions &QGrpcCallOptions::setFilterServerMetadata(bool value)

If value is `true`, protocol-related metadata defined by the gRPC transport (such as reserved `grpc-` keys) will be excluded. If value is `false`, all metadata received from the server will be included.

*/ void QGrpcCommonOptions::setFilterServerMetadata(bool value) { m_filterServerMetadata = value; }

QT_END_NAMESPACE

Note: Setting this field overrides the corresponding channel options field — see QGrpcChannelOptions::setFilterServerMetadata()

This function was introduced in Qt 6.11.

See also filterServerMetadata() and QGrpcChannelOptions::setFilterServerMetadata().

### `[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.