Qt QML模块提供的重要C++类

Important C++ Classes Provided By The Qt QML Module

Qt QML模块提供的重要C++类

The Qt QML module provides C++ classes which implement the QML framework. Clients can use these classes to interact with the QML run-time (for example, by injecting data or invoking methods on objects), and to instantiate a hierarchy of objects from a QML document. The Qt QML module provides more C++ API than just the classes listed here, however the classes listed here provide the foundations of the QML runtime and the core concepts of QML.

​Qt-QML模块提供了实现QML框架的C++类。客户机可以使用这些类与QML运行时交互(例如,通过在对象上注入数据或调用方法),并从QML文档实例化对象的层次结构。Qt QML模块提供的C++API比这里列出的类更多,但是这里列出的类提供了QML运行时的基础和QML的核心概念。

QML Runtime

QML运行时

A typical QML application with a C++ entry-point will instantiate a QQmlEngine and then use a QQmlComponent to load a QML document. The engine provides a default QQmlContext which will be the top-level evaluation context used for evaluating functions and expressions defined in the QML document. The object hierarchy defined in the QML document will be instantiated by calling the create() function of the QQmlComponent instance, assuming that no errors were encountered during document loading.

​具有C++入口点的典型QML应用程序将实例化QQmlEngine,然后使用QQmlComponent加载QML文档。引擎提供一个默认的QQmlContext,它将是用于计算QML文档中定义的函数和表达式的顶级计算上下文。假设在文档加载过程中没有遇到错误,那么将通过调用QQmlComponent实例的create()函数来实例化QML文档中定义的对象层次结构。

The client may wish to modify the QQmlContext provided by the engine, by injecting properties or objects into the context. They can call the QQmlEngine::rootContext() function to access the top-level context.

​客户端可能希望通过向上下文中注入属性或对象来修改引擎提供的QQmlContext。他们可以调用QQmlEngine::rootContext()函数来访问顶级上下文。

After instantiating the object, the client will usually pass control to the application event loop so that user input events (like mouse-clicks) can be delivered and handled by the application.

实例化对象后,客户端通常会将控制权传递给应用程序事件循环,以便应用程序可以传递和处理用户输入事件(如鼠标单击)。

Note: The Qt Quick module provides a convenience class, QQuickView, which provides a QML runtime and visual window for displaying a QML application.

注意:Qt Quick模块提供了一个方便的类QQuickView,它提供了用于显示QML应用程序的QML运行时和可视窗口。

The QQmlEngine Class

QQmlEngine类

The QQmlEngine class provides an engine which can manage a hierarchy of objects which is defined in a QML document. It provides a root QML context within which expressions are evaluated, and ensures that properties of objects are updated correctly when required.

​QQmlEngine类提供了一个引擎,可以管理QML文档中定义的对象层次结构。它提供了一个根QML上下文,在该上下文中计算表达式,并确保在需要时正确更新对象的属性。

QQmlEngine allows the configuration of global settings that apply to all of the objects it manages; for example, the QNetworkAccessManager to be used for network communications, and the file path to be used for persistent storage.

​QQmlEngine允许配置适用于其管理的所有对象的全局设置;例如,用于网络通信的QNetworkAccessManager,以及用于持久存储的文件路径。

See the QQmlEngine class documentation for in-depth information about what the QQmlEngine class provides, and how it can be used in an application.

​有关QQmlEngine类提供了什么以及如何在应用程序中使用它的详细信息,请参阅QQmlEngine类文档。

The QQmlContext Class

QQmlContext类

The QQmlContext class provides a context for object instantiation and expression evaluation. All objects are instantiated in a particular context, and all of the expressions which are evaluated while an application is running are evaluated within a particular context. This context defines how symbols are resolved, and thus which values the expression operates on.

​QQmlContext类为对象实例化和表达式计算提供上下文。所有对象都在特定上下文中实例化,并且在应用程序运行时计算的所有表达式都在特定上下文中计算。此上下文定义如何解析符号,从而定义表达式操作的值。

See the QQmlContext class documentation for in-depth information about how to modify the evaluation context of an object by adding or removing properties of a QQmlContext, and how to access the context for an object.

​有关如何通过添加或删除QQmlContext的属性来修改对象的计算上下文,以及如何访问对象的上下文的详细信息,请参阅QQmlContext类文档。

Dynamic Object Instantiation and Expression Evaluation

动态对象实例化和表达式求值

Dynamic object instantiation and dynamic expression evaluation are both core concepts in QML. QML documents define object types which can be instantiated at run-time using a QQmlComponent. An instance of the QQmlComponent class can be created in C++ directly, or via the Qt.createComponent() function in imperative QML code. Arbitrary expressions can be calculated in C++ via the QQmlExpression class, and such expressions can interact directly with the QML context.

​动态对象实例化和动态表达式求值都是QML的核心概念。QML文档定义了可以在运行时使用QQmlComponent实例化的对象类型。QQmlComponent类的实例可以直接在C++中创建,也可以通过QML代码中的Qt.createComponent()函数创建。可以通过QQmlExpression类在C++中计算任意表达式,并且此类表达式可以直接与QML上下文交互。

The QQmlComponent Class

QQmlComponent类

The QQmlComponent class can be used to load a QML document. It requires a QQmlEngine in order to instantiate the hierarchy of objects defined in the QML document.

​QQmlComponent类可用于加载QML文档。它需要一个QQmlEngine来实例化QML文档中定义的对象层次结构。

See the QQmlComponent class documentation for in-depth information about how to use QQmlComponent.

​有关如何使用QQmlComponent的详细信息,请参阅QQmlComponent类文档。

The QQmlExpression Class

QQmlExpression类

The QQmlExpression class provides a way for clients to evaluate JavaScript expressions from C++, using a particular QML evaluation context. This allows clients to access QML objects by id, for example. The result of the evaluation is returned as a QVariant, and the conversion rules are defined by the QML engine.

​QQmlExpression类为客户端提供了一种使用特定的QML计算上下文从C++计算JavaScript表达式的方法。例如,这允许客户端通过id访问QML对象。评估结果作为QVariant返回,转换规则由QML引擎定义。

See the QQmlExpression class documentation for in depth information about how to use QQmlExpression in an application.

​有关如何在应用程序中使用QQmlExpression的详细信息,请参阅QQmlExpression类文档。

Usage of the Classes within QML Applications

QML应用程序中类的使用

These pages describe how to create QML applications which interact with the C++ classes:

这些页面描述了如何创建与C++类交互的QML应用程序:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值