QT_QML_GENERATE_ANDROID_JAVA_CLASS

Marks a QML file for Java code generation.

该特性在 Qt 6.8 引入。

When using QML as a Android: View in Android via QtQuickView , you can choose the QML components to make available as generated Java classes usable from Android code. To mark a .qml file for code generation, set its QT_QML_GENERATE_ANDROID_JAVA_CLASS source property to TRUE . The source property must be set before creating the module.

注意: The .qml file name must start with an uppercase letter and define a QML component. This property is valid only if QT_ANDROID_GENERATE_JAVA_QTQUICKVIEW_CONTENTS 有定义。

The source file property can be set like so:

set_source_files_properties(MyMainItem.qml
    PROPERTIES QT_QML_GENERATE_ANDROID_JAVA_CLASS TRUE)
					

You can pass multiple files at once to set_source_files_properties:

set(plain_qml_files
    MyItem1.qml
    MyItem2.qml
    FancyButton.qml
)
set(qml_to_java_files
    MyMainItem.qml
    MyOtherMain.qml
)
set_source_files_properties(${qml_to_java_files}
    PROPERTIES QT_QML_GENERATE_ANDROID_JAVA_CLASS TRUE
)
qt_add_qml_module(myapp
    URI MyModule
    QML_FILES ${plain_qml_files} ${qml_to_java_files}
)
					

另请参阅 Naming Custom QML Object Types .