このページでは

QHttpServerResponder Class

HTTPサーバーから応答を送信するためのAPI。詳細...

ヘッダー: #include <QHttpServerResponder>
CMake: find_package(Qt6 REQUIRED COMPONENTS HttpServer)
target_link_libraries(mytarget PRIVATE Qt6::HttpServer)
qmake: QT += httpserver
以下のように: Qt 6.4

パブリック型

enum class StatusCode { Continue, SwitchingProtocols, Processing, Ok, Created, …, NetworkConnectTimeoutError }

パブリック関数

QHttpServerResponder(QHttpServerResponder &&other)
~QHttpServerResponder()
(since 6.11) bool isResponseCanceled() const
(since 6.5) void sendResponse(const QHttpServerResponse &response)
(since 6.8) void swap(QHttpServerResponder &other)
void write(QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(const QJsonDocument &document, QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(QIODevice *data, const QByteArray &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(QIODevice *data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(const QByteArray &data, const QByteArray &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(const QByteArray &data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
void write(const QJsonDocument &document, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
(since 6.8) void writeBeginChunked(const QByteArray &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)
(since 6.8) void writeBeginChunked(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
(since 6.8) void writeBeginChunked(const QHttpHeaders &headers, QList<QHttpHeaders::WellKnownHeader> trailers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
(since 6.8) void writeChunk(const QByteArray &data)
(since 6.8) void writeEndChunked(const QByteArray &data)
(since 6.8) void writeEndChunked(const QByteArray &data, const QHttpHeaders &trailers)

詳細な説明

HTTP クライアントへの書き込みを行う関数を提供し、JSON オブジェクトをシリアル化するためのオーバーロードが用意されています。また、HTTP ヘッダーやステータスコードの書き込みもサポートしています。

メンバー型のドキュメント

enum class QHttpServerResponder::StatusCode

HTTPステータスコード

定数値
QHttpServerResponder::StatusCode::Continue100
QHttpServerResponder::StatusCode::SwitchingProtocols101
QHttpServerResponder::StatusCode::Processing102
QHttpServerResponder::StatusCode::Ok200
QHttpServerResponder::StatusCode::Created201
QHttpServerResponder::StatusCode::Accepted202
QHttpServerResponder::StatusCode::NonAuthoritativeInformation203
QHttpServerResponder::StatusCode::NoContent204
QHttpServerResponder::StatusCode::ResetContent205
QHttpServerResponder::StatusCode::PartialContent206
QHttpServerResponder::StatusCode::MultiStatus207
QHttpServerResponder::StatusCode::AlreadyReported208
QHttpServerResponder::StatusCode::IMUsed226
QHttpServerResponder::StatusCode::MultipleChoices300
QHttpServerResponder::StatusCode::MovedPermanently301
QHttpServerResponder::StatusCode::Found302
QHttpServerResponder::StatusCode::SeeOther303
QHttpServerResponder::StatusCode::NotModified304
QHttpServerResponder::StatusCode::UseProxy305
QHttpServerResponder::StatusCode::TemporaryRedirect307
QHttpServerResponder::StatusCode::PermanentRedirect308
QHttpServerResponder::StatusCode::BadRequest400
QHttpServerResponder::StatusCode::Unauthorized401
QHttpServerResponder::StatusCode::PaymentRequired402
QHttpServerResponder::StatusCode::Forbidden403
QHttpServerResponder::StatusCode::NotFound404
QHttpServerResponder::StatusCode::MethodNotAllowed405
QHttpServerResponder::StatusCode::NotAcceptable406
QHttpServerResponder::StatusCode::ProxyAuthenticationRequired407
QHttpServerResponder::StatusCode::RequestTimeout408
QHttpServerResponder::StatusCode::Conflict409
QHttpServerResponder::StatusCode::Gone410
QHttpServerResponder::StatusCode::LengthRequired411
QHttpServerResponder::StatusCode::PreconditionFailed412
QHttpServerResponder::StatusCode::PayloadTooLarge413
QHttpServerResponder::StatusCode::UriTooLong414
QHttpServerResponder::StatusCode::UnsupportedMediaType415
QHttpServerResponder::StatusCode::RequestRangeNotSatisfiable416
QHttpServerResponder::StatusCode::ExpectationFailed417
QHttpServerResponder::StatusCode::ImATeapot418
QHttpServerResponder::StatusCode::MisdirectedRequest421
QHttpServerResponder::StatusCode::UnprocessableEntity422
QHttpServerResponder::StatusCode::Locked423
QHttpServerResponder::StatusCode::FailedDependency424
QHttpServerResponder::StatusCode::UpgradeRequired426
QHttpServerResponder::StatusCode::PreconditionRequired428
QHttpServerResponder::StatusCode::TooManyRequests429
QHttpServerResponder::StatusCode::RequestHeaderFieldsTooLarge431
QHttpServerResponder::StatusCode::UnavailableForLegalReasons451
QHttpServerResponder::StatusCode::InternalServerError500
QHttpServerResponder::StatusCode::NotImplemented501
QHttpServerResponder::StatusCode::BadGateway502
QHttpServerResponder::StatusCode::ServiceUnavailable503
QHttpServerResponder::StatusCode::GatewayTimeout504
QHttpServerResponder::StatusCode::HttpVersionNotSupported505
QHttpServerResponder::StatusCode::VariantAlsoNegotiates506
QHttpServerResponder::StatusCode::InsufficientStorage507
QHttpServerResponder::StatusCode::LoopDetected508
QHttpServerResponder::StatusCode::NotExtended510
QHttpServerResponder::StatusCode::NetworkAuthenticationRequired511
QHttpServerResponder::StatusCode::NetworkConnectTimeoutError599

メンバ関数のドキュメント

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

QHttpServerResponderのインスタンスをムーブコンストラクタで生成し、other が指していたのと同じオブジェクトを指すようにします。

[noexcept] QHttpServerResponder::~QHttpServerResponder()

QHttpServerResponder を破棄します。

[since 6.11] bool QHttpServerResponder::isResponseCanceled() const

クライアントがレスポンスをキャンセルした場合、true を返します。レスポンスがキャンセルされた際に、ハンドラを早期に終了できるようにするために使用されます。

この関数は Qt 6.11 で導入されました。

[since 6.5] void QHttpServerResponder::sendResponse(const QHttpServerResponse &response)

クライアントに対してHTTPのresponse を送信します。

この関数は Qt 6.5 で導入されました。

[noexcept, since 6.8] void QHttpServerResponder::swap(QHttpServerResponder &other)

QHttpServerResponder other をQHttpServerResponder に置き換えます。この操作は非常に高速で、失敗することはありません。

この関数は Qt 6.8 で導入されました。

void QHttpServerResponder::write(QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus を返します。

注:この関数は、HTTP Content-Typeヘッダーを"application/x-empty" に設定します。

void QHttpServerResponder::write(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus およびHTTPヘッダーheaders を返します。

void QHttpServerResponder::write(const QJsonDocument &document, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus と、JSONドキュメントdocument を返します。

注:この関数は、HTTP Content-Typeヘッダーを「"application/json" 」に設定します。

void QHttpServerResponder::write(QIODevice *data, const QByteArray &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus およびMIMEタイプmimeType で応答します。I/Oデバイスdata が応答の本文を提供します。data がシーケンシャルである場合、メッセージの本文はチャンク単位で送信されます。そうでない場合、この関数はすべてのコンテンツが利用可能であると見なし、一度にすべてを送信しますが、読み取りはチャンク単位で行われます。

注:この関数は 、data の所有権を取得します。

void QHttpServerResponder::write(QIODevice *data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus およびHTTPヘッダーheaders を返します。I/Oデバイスdata がレスポンスの本文を提供します。data がシーケンシャルである場合、メッセージの本文はチャンク単位で送信されます。そうでない場合、この関数はすべてのコンテンツが利用可能であるとみなして一度に送信しますが、読み取りはチャンク単位で行われます。

注:この関数は 、data の所有権を取得します。

void QHttpServerResponder::write(const QByteArray &data, const QByteArray &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus 、MIMEタイプmimeType 、および本文data を返します。

void QHttpServerResponder::write(const QByteArray &data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus 、HTTPヘッダーheaders 、および本文data を返します。

注:この関数は、HTTP Content-Lengthヘッダーを設定します。

void QHttpServerResponder::write(const QJsonDocument &document, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)

リクエストに対して、HTTPステータスコードstatus 、JSONドキュメントdocument 、およびHTTPヘッダーheaders を返します。

注:この関数は、HTTP Content-Typeヘッダーを"application/json" に設定します。

[since 6.8] void QHttpServerResponder::writeBeginChunked(const QByteArray &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)

MIMEタイプmimeType および指定されたステータスコードstatus を使用して、データのチャンクの送信を開始します。この呼び出しの後には、任意の回数のwriteChunk 呼び出しを繰り返し、その後、writeEndChunked を呼び出す必要があります。

この関数は Qt 6.8 で導入されました。

writeChunk およびwriteEndChunkedも参照してください 。

[since 6.8] void QHttpServerResponder::writeBeginChunked(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)

headers およびステータスコードstatus を使用して、データのチャンク送信を開始します。この呼び出しの後には、任意の回数のwriteChunk の呼び出しを繰り返し、最後にwriteEndChunked を 1 回呼び出す必要があります。

この関数は Qt 6.8 で導入されました。

writeChunk およびwriteEndChunkedも参照してください 。

[since 6.8] void QHttpServerResponder::writeBeginChunked(const QHttpHeaders &headers, QList<QHttpHeaders::WellKnownHeader> trailers, QHttpServerResponder::StatusCode status = StatusCode::Ok)

headers および指定されたステータスコードstatus を使用して、データのチャンクの送信を開始します。この呼び出しの後には、任意の回数のwriteChunk の呼び出しを繰り返した後、trailers で指定されたのと同じトレーラーを指定して、writeEndChunked を 1 回呼び出す必要があります。

この関数は Qt 6.8 で導入されました。

writeChunk およびwriteEndChunkedも参照してください 。

[since 6.8] void QHttpServerResponder::writeChunk(const QByteArray &data)

data をクライアントに書き戻します。書き込み可能なデータが用意されたときに呼び出されます。この関数は複数回呼び出される可能性がありますが、呼び出す前にwriteBeginChunked を呼び出し、その後writeEndChunked を呼び出す必要があります。

この関数は Qt 6.8 で導入されました。

writeBeginChunked およびwriteEndChunkedも参照してください 。

[since 6.8] void QHttpServerResponder::writeEndChunked(const QByteArray &data)

data をクライアントに書き戻します。その前に、writeBeginChunked を呼び出す必要があります。

この関数は Qt 6.8 で導入されました。

writeBeginChunked およびwriteChunkも参照してください 。

[since 6.8] void QHttpServerResponder::writeEndChunked(const QByteArray &data, const QHttpHeaders &trailers)

writeBeginChunked で発表されたtrailers を使用して、data をクライアントに書き戻します。

この関数は Qt 6.8 で導入されました。

writeBeginChunked およびwriteChunkも参照してください 。

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