Qt OpenAPI
Qt OpenAPI module provides functionality for generating Qt HTTP clients using Qt Network RESTful APIs. The main module features are the Qt6 OpenAPI generator and pre-generated OpenApiCommon library.
The Qt6 OpenAPI generator is a plugin to the OpenAPI generator. It allows you to autogenerate Qt HTTP clients in C++ using Qt Network APIs such as QRestAccessManager.
Note: Qt OpenAPI in 6.12 is in Technical Preview, excluding its API from Qt's compatibility promises.
Using the module
Installation of the following packages is necessary to use the Qt OpenAPI module:
- OpenAPI generator (requires OpenAPI 7.12.0 or above).
- Maven plugin (requires Maven 3.0 or above).
- Java JDK (requires JDK 17 or above).
Once you have the required installations, the Qt OpenAPI generator is ready for use within your projects. To generate client code from an OpenAPI specification using the Qt OpenAPI Generator, you should call the qt_add_openapi_client function inside your project's CMakeLists.txt file. See Building with CMake for details.
Building with CMake
Using the qt_add_openapi_client macro
Use the find_package() command to locate the needed module components in the Qt6 package. And after that call the qt_add_openapi_client function to generate a required Qt HTTP client library. See the full cmake code example below:
cmake_minimum_required(VERSION 3.22)
project(openapiApplication LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Core OpenApiCommon OpenApiTools)
qt_add_executable(openapiApplication
main.cpp
)
qt_add_library(generatedLibrary)
qt_add_openapi_client(generatedLibrary
SPEC_FILE
${CMAKE_CURRENT_SOURCE_DIR}/spec.yaml
)
target_link_libraries(openapiApplication Qt6::Core generatedLibrary)
include(GNUInstallDirs)
install(TARGETS openapiApplication
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)Note: OpenApiTools library doesn't need to be linked to the resulting openapiApplication target. However, it's still required for enabling the qt_add_openapi_client cmake function.
Note: OpenApiCommon library is linked to the target by the qt_add_openapi_client call.
Calling the Qt OpenAPI Generator from the command line
To generate client code from an OpenAPI specification using the Qt OpenAPI Generator, you should run the following command:
java -cp <path-to-installed-openapigen>/openapi-generator-cli.jar:<path-to-installed-qt>/<qt-version>/libexec/cpp-qt6-client-openapi-generator-1.0.0.jar \
org.openapitools.codegen.OpenAPIGenerator \
generate -g cpp-qt6-client \
--additional-properties=cppCommonNamespace=QtOpenApiCommon,prefix=QOAI \
-o generator_output/ -i file.yamlThe command above adds the Qt 6 OpenAPI generator to the classpath, which makes it visible to the upstream OpenAPI generator, then invokes main class org.openapitools.codegen.OpenAPIGenerator. Setting the Qt 6 generator's name cpp-qt6-client to the -g parameter makes sure it will be found and called.
To generate client code from an extra large OpenAPI specification file, add the maxYamlCodePoints option to the command line, see below:
java -DmaxYamlCodePoints=99999999 <other arguments>Note: Always add --additional-properties=cppCommonNamespace=QtOpenApiCommon,prefix=QOAI if you want to link the pre-generated Qt6::OpenApiCommon library to the project, because it was built with these parameters, and you'll get compilation errors if you provide different values.
The generator creates the client library in the generator_output folder. Add the generator_output folder to the project, like in an example below:
find_package(Qt6 REQUIRED COMPONENTS Core OpenApiCommon)
add_subdirectory(generator_output/client)
add_executable(example_binary
main.cpp
)
target_link_libraries(Qt6OpenAPIClient PUBLIC Qt6::OpenApiCommon)
target_link_libraries(example_binary PRIVATE Qt6::Core Qt6OpenAPIClient)If you want to see all generation options, you can use the config-help option, see below:
java -cp <path-to-installed-openapigen>/openapi-generator-cli.jar:<path-to-installed-qt>/<qt-version>/libexec/cpp-qt6-client-openapi-generator-1.0.0.jar \
org.openapitools.codegen.OpenAPIGenerator config-help -g cpp-qt6-clientNote: You can find more information about the generator usage in the OpenAPI generator documentation.
Examples
Licenses and Attributions
© 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.