QT_QML_GENERATE_ANDROID_JAVA_CLASS

用于标记需生成 Java 代码的 QML 文件。

该属性在 Qt 6.8 中引入。

当通过QtQuickView 将 QML 用作Android 的“视图”时,您可以选择哪些 QML 组件将作为生成的 Java 类,以便在 Android 代码中使用。要标记一个.qml 文件以进行代码生成,请将其QT_QML_GENERATE_ANDROID_JAVA_CLASS 源属性设置为TRUE 。该源属性必须在创建模块之前设置。

注意: .qml 文件名必须以大写字母开头,并定义一个 QML 组件。只有在定义了QT_ANDROID_GENERATE_JAVA_QTQUICKVIEW_CONTENTS时,此属性才有效。

源文件属性可按以下方式设置:

set_source_files_properties(MyMainItem.qml
    PROPERTIES QT_QML_GENERATE_ANDROID_JAVA_CLASS TRUE)

您可以一次向 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}
)

另请参阅 《自定义 QML 对象类型的命名》。

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