The Component element encapsulates a QML component definition. More...
Component元素封装了一个QML组件的定义。
Component instantiates the C++ class QDeclarativeComponent
Component实例化了C++类QDeclarativeComponent
Components are reusable, encapsulated QML elements with well-defined interfaces.
Component具有可重用性,封装好的具有良好接口定义的QML元素。
Components are often defined by component files - that is, .qml files. The Component element essentially allows QML components to be defined inline, within aQML document, rather than as a separate QML file. This may be useful for reusing a small component within a QML file, or for defining a component that logically belongs with other QML components within a file.
通常来说component被定义在组件文件中——就是.qml文件。Component 元素允许QML组件被定义在内部,在一个QML文档而不是独立的QML文件。这有利于在文件中重用小的组件,或者有利于定义一个组件逻辑上属于这个文件里其他QML组件。
For example, here is a component that is used by multiple Loader objects. It contains a single item, a Rectangle:
例如,这里component被多个Loader对象使用。它包含一个单个item,一个Rectangle。
Notice that while a Rectangle by itself would be automatically rendered and displayed, this is not the case for the above rectangle because it is defined inside aComponent. The component encapsulates the QML elements within, as if they were defined in a separate QML file, and is not loaded until requested (in this case, by the two Loader objects).
注意虽然Rectangle元素会自动渲染和显示,但对于上例中的情况则有点特殊。上面的例子中rectangle是在一个组件(component)中定义的。组件包含的一些QML元素,好像这些元素在另外一个QML文件中定义似地,只要当需要的时候才会执行加载。
Defining a Component is similar to defining a QML document. A QML document has a single top-level item that defines the behaviors and properties of that component, and cannot define properties or behaviors outside of that top-level item. In the same way, a Component definition contains a single top level item (which in the above example is a Rectangle) and cannot define any data outside of this item, with the exception of an id (which in the above example isredSquare).
定义一个Component类似于定义一个QML文档。一个QML文档有单个的顶层item,定义了这个组件的行为和属性,不能在这个顶层item外面定义行为和属性。同样,Component定义包含了一个单独的顶层item(上面例子中是Rectangle),不能在这个item外面定义任何数据,除了id(上面的例子是redSquare)。
(一个组件只能包含一个id属性和一个顶层的item,其中id是可选的但item必须定义,不能定义一个空的组件。)
The Component element is commonly used to provide graphical components for views. For example, the ListView::delegate property requires a Component to specify how each list item is to be displayed.
组件通常是从视图的提取出的公共部分。例如ListView::delegate属性需要指定一个组件来绘制列表的每一项。
Component objects can also be created dynamically using Qt.createComponent().
组件对象还可以通过调用Qt.createComponent()来动态创建一个组件对象。
read-onlyprogress : real |
The progress of loading the component, from 0.0 (nothing loaded) to 1.0 (finished).
表明加载组件的进度。0.0表示没有加载,1.0表示加载完毕。
read-onlystatus : enumeration |
This property holds the status of component loading. It can be one of:
status表明组件加载的状态。有以下可选值:
Component.Null - no data is available for the component
Component.Null—— 表明没有设置需要加载的QML数据。
Component.Ready - the component has been loaded, and can be used to create instances.
Component.Ready ——表明QML数据已经加载完毕,可以用于创建实例。
Component.Loading - the component is currently being loaded
Component.Loading 表明正在加载QML数据。
Component.Error - an error occurred while loading the component. Calling errorString() will provide a human-readable description of any errors.
Component.Error—— 表明加载QML数据时出错,调用errorString() 可以提供错误提示。
read-onlyurl : url |
The component URL. This is the URL that was used to construct the component.
组件的URL可被用于构建这个组件。
Emitted after component "startup" has completed. This can be used to execute script code at startup, once the full QML environment has been established.
The Component::onCompleted attached property can be applied to any element. The order of running the onCompleted scripts is undefined.
当组件启动完成后onCompleted()信号会被发送。我们可以在启动后执行一些代码。 附属属性Component::onCompleted 能被任何元素应用。onCompleted 的运行顺序是未定的。
Emitted as the component begins destruction. This can be used to undo work done in the onCompleted signal, or other imperative code in your application.
当组件析构时会发送onDestruction ()信号。可用于执行undo操作,或其它必需的代码。
The Component::onDestruction attached property can be applied to any element. However, it applies to the destruction of the component as a whole, and not the destruction of the specific object. The order of running the onDestruction scripts is undefined.
附属属性Component::onDestruction 可被其他任何代码应用。然而,它适用于这个组件的整体的析构,而不是指定对象的析构。onDestruction 运行顺序未定。
object Component::createObject ( Item parent ) |
Creates and returns an object instance of this component that will have the given parent. Returns null if object creation fails.
创建一个以parent为父item的组件的对象实例病返回它。如果创建失败则返回null。
The object will be created in the same context as the one in which the component was created. This function will always return null when called on components which were not created in QML.
被创建对象的上下文和这个组件是相同的,如果不是被创建在QML中,则返回null。
If you wish to create an object without setting a parent, specify null for the parent value. Note that if the returned object is to be displayed, you must provide a valid parent value or set the returned object's parent property, or else the object will not be visible.
如果你希望创建的对象不设置父对象,则指定parent的值为null。注意如果想让创建的组件显示,则需要指定一个合法的父item(非null的)或是手动为创建的对象设置一个合法的父item,否则创建的组件将不会显示。
Dynamically created instances can be deleted with the destroy() method. See Dynamic Object Management in QML for more information.
动态创建的实例能被destroy() 方法删除。
string Component::errorString () |
Returns a human-readable description of any errors.
返回可读的错误信息。
The string includes the file, location, and description of each error. If multiple errors are present they are separated by a newline character.
错误信息中包括错误发生所在的文件,所在的行以及错误信息描述。每个错误的错误信息会占用一行。
If no errors are present, an empty string is returned.
联系客服