Qt Quick for Android | Qt Quick | Qt 6.11.0
Description: An overview on using QML in native Android projects.

- Qt 6.11
- Qt Quick
- Qt Quick for Android
- Qt 6.11.0 Reference Documentation

Shared image provider ◦ Qt Quick Android Classes

# Qt Quick for Android

## Qt Quick for Android overview

The basis of this approach is to offer Qt QML APIs in an embedded way so that the app will remain a relatively typical Android app. This approach offers a more standard Android-centered approach at the cost of leveraging the cross-platform nature of a Qt application. It's best suited for adding desirable Qt features to an existing Android application.

- Android creates the Qt content and controls it.
- Android Studio with the Qt Tools for Android Studio plugin is used for development.
- For Qt content, Qt Creator or Qt Design Studio are used.
- Main languages are Java and Kotlin, with QML used for specific parts such as 3D content.
- You can use any Android APIs you want, but you can use JNI if you want more control over communication between your Java code and QML. See QJniObject and QJniEnvironment.

### How this differs from Qt for Android

The most prominent difference between these approaches is the project structure. Qt for Android applications are CMake projects that can be built for Android or other platforms, while a Qt Quick for Android Project is an Android project that includes QML content and can only be built for Android.

The main objective of the Qt for Android approach is to let Qt handle most of the work of the architecture and boilerplate code of the app and let you focus on the content. It offers a complete and reliable cross-platform approach.

- Qt creates and controls the Android app.
- Qt Creator, Qt Design Studio, or Visual Studio can be used.
- Main languages are C++ and QML.
- Android specifics are more hidden; Qt handles these internally.
- To use Android APIs not yet available as Qt APIs, you must use JNI. See QJniObject and QJniEnvironment.

See How Qt for Android Works for further details on Qt for Android's architecture.

## How Qt Quick for Android works

Qt Quick for Android offers you Android APIs that enable you to insert QML content as an Android View in your project.

## APIs

These are the public Java and Kotlin APIs that you will use in an Android app to embed QML.

### Java classes

- QtQuickView
- QtQuickViewContent
- QtAbstractItemModel
- QtAbstractListModel
- QtModelIndex

### Interfaces

- QtQmlStatusChangeListener (which uses the QtQmlStatus enum)

Note: See the QT_ANDROID_GENERATE_JAVA_QTQUICKVIEW_CONTENTS CMake variable for further information on Java code generation of QML components.

## API examples

- Qt Quick for Android Studio Projects
- Exposing QtAbstractListModel to QML
- Using QtAbstractItemModel in Android Studio Projects

## Changes in `main()` are required by Qt Quick for Android APIs

A typical Qt Quick application's main.cpp appears like this:

     #include <QGuiApplication>
     #include <QQmlApplicationEngine>

     int main(int argc, char *argv[])
     {
         QGuiApplication app(argc, argv);

         QQmlApplicationEngine engine;
         QObject::connect(
             &engine,
             &QQmlApplicationEngine::objectCreationFailed,
             &app,
             []() { QCoreApplication::exit(-1); },
             Qt::QueuedConnection);
         engine.loadFromModule("MyQtQuickProject", "Main");

         return app.exec();
     }

In `main()` we don't need to create a QML Engine or load any QML that will be handled later by the Qt Quick View APIs. All that we need is in `main()` is:

     #include <QGuiApplication>

     int main(int argc, char *argv[])
     {
         QGuiApplication app(argc, argv);

         return app.exec();
     }

### Running Qt Quick for Android examples

## Qt Quick for Android API examples are Android Studio Projects

The Qt Quick for Android API examples are provided as Android Studio projects. The project folders are found in your Qt install location.

For example, under the default Windows install path, they are found here:

     C:\Qt\Examples\Qt-<patch-release-number>\platforms\android\<example-name>

These projects are already configured to use a version of the Qt Gradle Plugin compatible with this Qt version.

## Tooling

The Qt Gradle Plugin and Qt Tools for Android Studio plugin are provided by Qt for easy development. You can use the Gradle Plugin independently from an IDE as part of your build toolchain. Qt Tools for Android Studio uses the plugin to build your projects in Android Studio.

## Where to go from here

The following additional topics apply to Qt Quick For Android:

Android Fragments with Qt Quick for Android | Tutorial on using Qt Quick Views in Android Fragments

Shared image provider ◦ Qt Quick Android Classes