On this page

QGrpcBidiStream Class

The QGrpcBidiStream class provides access in handling bidirectional-streaming RPCs. More...

Header: #include <QGrpcBidiStream>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Since: Qt 6.7
Inherits: QGrpcOperation

Public Functions

virtual ~QGrpcBidiStream() override
(since 6.13) quint64 bytesToWrite() const
void writeMessage(const QProtobufMessage &message)
(since 6.8) void writesDone()

Signals

void messageReceived()
(since 6.13) void messageWritten()

Detailed Description

The QGrpcBidiStream class provides the interface for handling bidirectional-streaming remote procedure calls (RPCs), which is one of the four gRPC service methods.

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

Note: Users are responsible for managing the unique RPC handlers returned by the Client interface, ensuring their existence at least until the finished signal is emitted. After receiving this signal, the handler can be safely reassigned or destroyed.

Member Function Documentation

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

Destroys the QGrpcBidiStream.

[noexcept, since 6.13] quint64 QGrpcBidiStream::bytesToWrite() const

Returns the number of bytes the channel has accepted for this stream but not yet written to the transport. QGrpcHttp2Channel reports the wire size of the queued messages, including the message currently in transmission, after framing and optional compression.

The value changes as writeMessage() accepts messages and the transport consumes them; check it in a messageWritten() handler to decide whether to write more messages or wait, and to bound the memory the outgoing queue may occupy.

This function was introduced in Qt 6.13.

See also messageWritten() and writeMessage().

[signal] void QGrpcBidiStream::messageReceived()

This signal is emitted when the streaming RPC has received a new message from the server. The read() methods can then be used to deserialize the received message.

[signal, since 6.13] void QGrpcBidiStream::messageWritten()

This signal is emitted when the channel has passed an outgoing message on to the transport: once for the initial request message and once per writeMessage() call, in write order.

QGrpcHttp2Channel emits it after the message has been fully written to the connection, which respects HTTP/2 flow control; when the server stops consuming data, the emission is delayed until the server grants more send window.

Messages queue up without limit when they are written faster than the network transmits them. To bound the queue, write the next message only after this signal reports the previous one written, matching the write-then-wait discipline commonly seen in gRPC implementations.

For medium and large messages this one-at-a-time pacing costs no throughput, and usually improves it by avoiding a large backlog. For very small, high-rate messages the per-message wait can dominate instead; there, keep a few messages in flight: write a small batch up front and write one more on each emission. bytesToWrite() reports how much of the written data still awaits transmission.

Once finished() has been emitted the signal is not emitted anymore, even for messages that were still in transmission when the operation ended.

This function was introduced in Qt 6.13.

See also writeMessage().

void QGrpcBidiStream::writeMessage(const QProtobufMessage &message)

Serializes message and sends it to the server.

Messages are queued and handed to the transport. The queue is unbounded, so pace high-rate writes using the messageWritten() signal.

See also messageWritten().

[since 6.8] void QGrpcBidiStream::writesDone()

Ends the stream from the client side (half-closing). The server is still allowed to send responses after this call.

This function was introduced in Qt 6.8.

© 2026 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.