QFormDataBuilder Class

The QFormDataBuilder class is a convenience class to simplify the construction of QHttpMultiPart objects. More...

Header: #include <QFormDataBuilder>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network
Since: Qt 6.8

Public Functions

QFormDataBuilder()
QFormDataBuilder(QFormDataBuilder &&other)
~QFormDataBuilder()
std::unique_ptr<QHttpMultiPart> buildMultiPart()
QFormDataPartBuilder part(QAnyStringView name)
QFormDataBuilder &operator=(QFormDataBuilder &&other)

Detailed Description

The QFormDataBuilder class can be used to build a QHttpMultiPart object with the content type set to be FormDataType by default.

The snippet below demonstrates how to build a multipart message with QFormDataBuilder:

QFormDataBuilder builder;
QFile image(u"../../pic.png"_s); image.open(QFile::ReadOnly);
QFile mask(u"../../mask.png"_s); mask.open(QFile::ReadOnly);

builder.part("image"_L1).setBodyDevice(&image, "the actual image");
builder.part("mask"_L1).setBodyDevice(&mask, "the mask image");
builder.part("prompt"_L1).setBody("Lobster wearing a beret");
builder.part("n"_L1).setBody("2");
builder.part("size"_L1).setBody("512x512");

std::unique_ptr<QHttpMultiPart> mp = builder.buildMultiPart();

See also QHttpPart, QHttpMultiPart, and QFormDataPartBuilder.

Member Function Documentation

QFormDataBuilder::QFormDataBuilder()

Constructs an empty QFormDataBuilder object.

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

Move-constructs a QFormDataBuilder instance, making it point at the same object that other was pointing to.

[noexcept] QFormDataBuilder::~QFormDataBuilder()

Destroys the QFormDataBuilder object.

std::unique_ptr<QHttpMultiPart> QFormDataBuilder::buildMultiPart()

Constructs and returns a pointer to a QHttpMultipart object.

See also QHttpMultiPart.

QFormDataPartBuilder QFormDataBuilder::part(QAnyStringView name)

Returns a newly-constructed QFormDataPartBuilder object using name as the form-data's name parameter. The object is valid for as long as the associated QFormDataBuilder has not been destroyed.

Limiting name characters to US-ASCII is strongly recommended for interoperability reasons.

See also QFormDataPartBuilder and QHttpPart.

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

Move-assigns other to this QFormDataBuilder instance.

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