Skip to content

[cpp-qt-client]Optimize generated code#23089

Open
martonmiklos wants to merge 3 commits intoOpenAPITools:masterfrom
martonmiklos:optimize_generated_qt_client_code
Open

[cpp-qt-client]Optimize generated code#23089
martonmiklos wants to merge 3 commits intoOpenAPITools:masterfrom
martonmiklos:optimize_generated_qt_client_code

Conversation

@martonmiklos
Copy link
Contributor

@martonmiklos martonmiklos commented Mar 1, 2026

  • Use const references at function parameters
  • Do not perform useless initialization of QStrings
  • Use qDeleteAll instead of custom loop

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Optimized the generated Qt C++ client to reduce copies and enforce const-correctness in internal code, without changing the public API. Regenerated samples/tests and updated docs accordingly.

  • Refactors
    • Use const QString& across internal APIs: model/object/enum constructors and fromJson, HttpRequestInput (ctor/add_var/add_file), http_attribute_encode; OAuth getToken/removeToken/setVariables; ReplyServer::setReply now takes const QByteArray&.
    • Remove redundant QString initializations; switch delete loops to qDeleteAll; iterate with const refs and std::as_const; add missing headers (, ); reduce response string copying.
    • Update samples and README examples; regenerate tests (including Kotlin polymorphism sample adjustments).

Written for commit 98c42be. Summary will update on new commits.

@martonmiklos martonmiklos force-pushed the optimize_generated_qt_client_code branch from 32ecb3b to 88f4855 Compare March 1, 2026 23:26
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 67 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.cpp.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.cpp.mustache:61">
P2: qDeleteAll is used but <QtAlgorithms> isn’t included, which can cause compilation errors when the symbol isn’t provided transitively by other Qt headers.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.cpp.mustache:421">
P3: std::as_const requires <utility>; this file does not include it, so compilation can fail if transitive includes change. Add #include <utility>.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Use const references at function parameters
- Do not perform useless initialization of QStrings
- Use qDeleteAll
@martonmiklos martonmiklos force-pushed the optimize_generated_qt_client_code branch from 88f4855 to 427455e Compare March 2, 2026 08:15
@wing328
Copy link
Member

wing328 commented Mar 3, 2026

thanks for the PR

moving forward, please cc the technical committee for review

@ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @MartinDelille (2018/03) @muttleyxd (2019/08) @aminya (2025/05)

Copy link
Contributor

@MartinDelille MartinDelille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with these changes, there is just this question about the change in the signal signature that was already address previously with a new signal. I tested the signature change here without issue so we could also keep both signalE and signalError with const parameter. We could also either:

  • remove the deprecation
  • remove the signalE (which would break for people that accepted deprecated function)

@martonmiklos
Copy link
Contributor Author

I'm fine with these changes, there is just this question about the change in the signal signature that was already address previously with a new signal. I tested the signature change here without issue so we could also keep both signalE and signalError with const parameter. We could also either:

* remove the deprecation

* remove the signalE (which would break for people that accepted deprecated function)

I have rollbacked my changes in the signal arguments, I think deprecation should be done in a separate PR.

Thank you very much for your review!

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 16 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/cpp-qt/client/PFXPetApi.h">

<violation number="1">
P2: Deprecated signal signatures were changed from `const QString&` to `QString`, which alters the public API/ABI and can break existing code that connects using the old signal signature or precompiled binaries.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@MartinDelille
Copy link
Contributor

Deprecated signals removed here: #23113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants