On this page

Qt Jenny: Java Code Generator

Qt Jenny translates Java APIs to Qt C++ wrappers, allowing Qt C++ programs to invoke Java functionality. This is particularly useful on a platform with Java system APIs, like Android.

Features

Qt Jenny's features:

  • Generation of wrappers for any Java class.
  • Templated generation with customizable templates that can be changed to customize the C++ output.
  • Configurable generation that allows controlling the namespace of the generated wrappers.
  • Support for generating code that uses QJniObject in the generated code, therefore utilizing all the convenience QJniObject brings.

Examples

See QtJenny Demo for an example how to use Qt Jenny.

How Qt Jenny works

Qt Jenny translates Java APIs to Qt C++ wrappers by the use of the following building blocks:

  • Kotlin code that imports the classes to be wrapped.
  • Annotations in that code that tell which classes to wrap.
  • A code generator that reads the annotations and generates the wrapper code.

With these building blocks, the Qt project is then structured so that there's a separate Gradle project for generating the code that the Qt CMake project uses. The CMake project triggers the code generation at project configuration time (in other words, when you run CMake). For an application that invokes methods but does not need to implement any callbacks, a single code-generation project is enough. For an application that uses both method invocations and interface callbacks, two generation projects are needed: one for the method proxies and one for the callback hierarchy. For an application that needs to extend classes, three generation projects are needed: one for the method proxies, one for the Java glue code, and one for the callback hierarchy.

The example code in QtJenny Demo uses three generation projects, since it uses class extension.

How it works

Reference

Licenses and Attributions

Qt Jenny potentially contains third-party modules under the following permissive licenses:

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