qt_qml_generate_android_java_class
标记用于生成 Java 代码的 QML 文件。
该属性在 Qt 6.8 中引入。
当通过 QtQuickView 在Android中将 QML 作为Android.View 使用时,该属性可用于生成 Java 代码:在 Android 中通过QtQuickView 将 QML 作为视图使用时,您可以选择 QML 组件作为可从 Android 代码生成的 Java 类使用。要将.qml
文件标记为代码生成,请将其QT_QML_GENERATE_ANDROID_JAVA_CLASS
source 属性设置为TRUE
。必须在创建模块前设置 source 属性。
注意: .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 对象类型。
© 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.