Qt QML
The Qt QML module provides a framework for developing applications and libraries with the QML language. It defines and implements the language and engine infrastructure, and provides an API to enable application developers to extend the QML language with custom types and integrate QML code with JavaScript and C++. The Qt QML module provides both a QML API and a C++ API.
Qt-QML模块为使用QML语言开发应用程序和库提供了一个框架。它定义并实现了语言和引擎基础设施,并提供了一个API,使应用程序开发人员能够使用自定义类型扩展QML语言,并将QML代码与JavaScript和C++集成。Qt QML模块同时提供QML API和C++API。
Note that while the Qt QML module provides the language and infrastructure for QML applications, the Qt Quick module provides many visual components, model-view support, an animation framework, and much more for building user interfaces.
请注意,虽然Qt-QML模块为QML应用程序提供了语言和基础设施,但Qt-Quick模块为构建用户界面提供了许多可视化组件、模型视图支持、动画框架等。
If you're new to QML and Qt Quick, see QML Applications for an introduction to writing QML applications.
如果您是QML和Qt Quick的新手,请参阅QML应用程序,了解编写QML应用程序的介绍。
Using the Module
使用模块
QML API
The QML types of the module are available through the QtQml
import. To use the types, add the following import statement to your .qml file:
该模块的QML类型可通过QtQml导入获得。要使用这些类型,请将以下导入语句添加到。qml文件:
import QtQml
C++ API
Using a Qt module requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake.
使用Qt模块需要直接或通过其他依赖项链接模块库。有几个构建工具专门支持这一点,包括CMake和qmake。
Building with CMake
使用CMake构建
Use the find_package()
command to locate the needed module component in the Qt6
package:
使用find_package()命令在Qt6包中找到所需的模块组件:
find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
For more details, see the Build with CMake overview.
有关更多详细信息,请参阅使用CMake的构建概述。
To provide foreign QML type support for a non-QML library, locate the QmlIntegration
module as follows:
要为非QML库提供外部QML类型支持,请按以下方式找到QML集成模块:
find_package(Qt6 REQUIRED COMPONENTS QmlIntegration)
target_link_libraries(mytarget PRIVATE Qt6::QmlIntegration)
See qt6_generate_foreign_qml_types for details.
有关详细信息,请参阅qt6_generate_foreign_qml_type。
Building with qmake
用qmake构建
To configure the module for building with qmake, add the module as a value of the QT
variable in the project's .pro file:
要配置用于使用qmake构建的模块,请将该模块作为QT变量的值添加到项目的.pro文件:
QT += qml
QML and QML Types
QML和QML类型
The Qt QML module contains the QML framework and important QML types used in applications. The constructs of QML are described in the The QML Reference.
Qt QML模块包含QML框架和应用程序中使用的重要QML类型。QML的构造在QML参考中进行了描述。
In addition to the QML Basic Types, the module comes with the following QML object types:
除QML基本类型外,该模块还提供以下QML对象类型:
The Qt global object provides useful enums and functions for various QML types.
Qt全局对象为各种QML类型提供了有用的枚举和函数。
Lists and Models
列表和模型
New in Qt 5.1, the model types are moved to a submodule, QtQml.Models
. The Qt QML Models page has more information.
Qt 5.1中新增了模型类型,将其移动到子模块QtQml.Models中
。Qt QML模型页面有更多信息。
JavaScript Environment for QML Applications
QML应用程序的JavaScript环境
JavaScript expressions allow QML code to contain application logic. Qt QML provides the framework for running JavaScript expressions in QML and from C++.
JavaScript表达式允许QML代码包含应用程序逻辑。Qt-QML提供了在QML和C++中运行JavaScript表达式的框架。
These sections are from The QML Reference.
这些部分来自QML参考。
- Integrating QML and JavaScript
- Using JavaScript Expressions with QML
- Dynamic QML Object Creation from JavaScript
- Defining JavaScript Resources In QML
- Importing JavaScript Resources In QML
- JavaScript Host Environment
Integrating QML with C++ Applications
QML与C++应用程序的集成
The module also provides the framework for running QML applications. The QML framework allows QML code to contain JavaScript expressions and for the QML code to interact with C++ code.
该模块还提供了运行QML应用程序的框架。QML框架允许QML代码包含JavaScript表达式,并允许QML代码与C++代码交互。
Articles and Guides
文章和指南
- Overview - QML and C++ Integration
- Data Type Conversion Between QML and C++
- Exposing Attributes of C++ Types to QML
- Defining QML Types from C++
- Writing QML Modules
- Important C++ Classes Provided By The Qt QML Module
Examples
示例
Related Articles and Guides
相关文章和指南
Further information for writing QML applications:
QML的进一步信息:
- The QML Reference
- QML Applications - essential information for application development with QML and Qt Quick
使用QML和Qt Quick开发应用程序的基本信息
- Qt Quick - a module which provides a set of QML types and C++ classes for building user interfaces and applications with QML
一个模块,提供一组QML类型和C++类,用于使用QML构建用户界面和应用程序
- The QML Disk Cache - how to fine tune if and where the QML engine caches compilation results
如何微调QML引擎缓存编译结果的时间和位置
Examples
示例
Reference
参考文档
Licenses and Attributions
许可证和归属
Qt QML is available under commercial licenses from The Qt Company. In addition, it is available under free software licenses. Since Qt 5.4, these free software licenses are GNU Lesser General Public License, version 3, or the GNU General Public License, version 2. See Qt Licensing for further details.
Qt QML是根据Qt公司的商业许可证提供的。此外,它还有自由软件许可证。自Qt 5.4以来,这些自由软件许可证是GNU Lesser General Public许可证版本3或GNU General Public许可证版本2。有关更多详细信息,请参阅Qt许可。
Furthermore Qt QML in Qt 6.3.1 may contain third party modules under following permissive licenses:
此外,Qt 6.3.1中的Qt QML可能包含以下许可证下的第三方模块:
BSD 2-clause "Simplified" License |
© 2022 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.