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 應用程序的進一步信息: