Qt QML 模块为开发应用程序和库提供框架,采用 QML 语言 。它定义并实现语言和引擎基础设施,还提供 API 使应用程序开发者能够采用自定义类型扩展 QML 语言,及采用 JavaScript 和 C++ 集成 QML 代码。Qt QML 模块提供两者 QML API 和 C++ API .
注意,虽然 Qt QML 模块为 QML 应用程序提供了语言和基础设施,但 Qt Quick 模块为构建用户界面提供了更多视觉组件、模型 视图支持、动画框架、等。
If you're new to QML and Qt Quick, see QML 应用程序 了解编写 QML 应用程序的介绍。
The QML types of the module are available through the
QtQml
导入。要使用类型,添加以下 import 语句到 .qml 文件:
import QtQml
Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake .
使用
find_package()
command to locate the needed module component in the
Qt6
包:
find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
更多细节,见 构建采用 CMake 概述。
To provide foreign QML type support for a non-QML library, locate the
QmlIntegration
module as follows:
find_package(Qt6 REQUIRED COMPONENTS QmlIntegration) target_link_libraries(mytarget PRIVATE Qt6::QmlIntegration)
见 qt6_generate_foreign_qml_types 了解细节。
To configure the module for building with qmake, add the module as a value of the
QT
variable in the project's .pro file:
QT += qml
Qt QML 模块包含 QML 框架和用于应用程序的重要 QML 类型。QML 构造的描述是在 QML 参考 .
除了 QML Value Types ,模块带有以下 QML 对象类型:
The Qt 全局对象为各种 QML 类型提供有用枚举和函数。
从 Qt 5.1 起,将模型类型移到子模块
QtQml.Models
。
Qt QML 模型
页面有更多信息。
JavaScript 表达式允许 QML 代码包含应用程序逻辑。Qt QML 提供在 QML 和从 C++ 运行 JavaScript 表达式的框架。
这些章节来自 QML 参考 .
模块还提供运行 QML 应用程序的框架。QML 框架允许 QML 代码包含 JavaScript 表达式并允许 QML 代码与 C++ 代码进行交互。
Qt QML 在商业许可下是可用的来自 Qt 公司 。此外,它在自由软件许可下也是可用的。从 Qt 5.4 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。
Furthermore Qt QML in Qt 6.5.1 may contain third party modules under following permissive licenses:
| JavaScriptCore 宏汇编程序 | BSD 2 条款简化许可 |
用于编写 QML 应用程序的进一步信息: