Allows dynamic loading of a 3D subtree from a URL or Component. 更多...
导入语句: | import QtQuick3D |
继承: | Node |
Loader3D is used to dynamically load QML components for Qt Quick 3D.
Loader3D can load a QML file (using the source property) or a 组件 object (using the sourceComponent property). It is useful for delaying the creation of a component until it is required: for example, when a component should be created on demand, or when a component should not be created unnecessarily for performance reasons.
注意: Loader3D works the same way as Loader . The difference between the two is that Loader provides a way to dynamically load objects that inherit Item , whereas Loader3D provides a way to load objects that inherit Object3D and is part of a 3D scene.
active : bool |
此特性是
true
若
Loader3D
is currently active. The default value for this property is
true
.
若 Loader3D is inactive, changing the source or sourceComponent will not cause the item to be instantiated until the Loader3D is made active.
Setting the value to inactive will cause any item loaded by the loader to be released, but will not affect the source or sourceComponent .
status
of an inactive loader is always
Null
.
另请参阅 source and sourceComponent .
asynchronous : bool |
This property holds whether the component will be instantiated asynchronously. By default it is
false
.
When used in conjunction with the source property, loading and compilation will also be performed in a background thread.
Loading asynchronously creates the objects declared by the component across multiple frames, and reduces the likelihood of glitches in animation. When loading asynchronously the status will change to Loader3D .Loading. Once the entire component has been created, the item will be available and the status will change to Loader.Ready.
Changing the value of this property to
false
while an asynchronous load is in progress will force immediate, synchronous completion. This allows beginning an asynchronous load and then forcing completion if the
Loader3D
content must be accessed before the asynchronous load has completed.
To avoid seeing the items loading progressively set
visible
appropriately, e.g.
Loader3D { source: "mycomponent.qml" asynchronous: true visible: status == Loader3D.Ready }
Note that this property affects object instantiation only; it is unrelated to loading a component asynchronously via a network.
[read-only] item : object |
This property holds the top-level object that is currently loaded.
[read-only] progress : real |
This property holds the progress of loading QML data from the network, from 0.0 (nothing loaded) to 1.0 (finished). Most QML files are quite small, so this value will rapidly change from 0 to 1.
另请参阅 status .
source : url |
This property holds the URL of the QML component to instantiate.
To unload the currently loaded object, set this property to an empty string, or set
sourceComponent
to
undefined
. Setting
source
to a new URL will also cause the item created by the previous URL to be unloaded.
另请参阅 sourceComponent , status ,和 progress .
sourceComponent : 组件 |
此特性保持 组件 to instantiate.
Item { Component { id: redCube Model { source: "#Cube" materials: DefaultMaterial { diffuseColor: "red" } } } Loader3D { sourceComponent: redCube } Loader3D { sourceComponent: redCube; x: 10 } }
To unload the currently loaded object, set this property to
undefined
.
[read-only] status : enumeration |
This property holds the status of QML loading. It can be one of:
常量 | 描述 |
---|---|
Loader3D.Null
|
The loader is inactive or no QML source has been set. |
Loader3D.Ready
|
The QML source has been loaded. |
Loader3D.Loading
|
The QML source is currently being loaded. |
Loader3D.Error
|
An error occurred while loading the QML source. |
Use this status to provide an update or respond to the status change in some way. For example, you could:
State { name: 'loaded'; when: loader.status == Loader3D.Ready }
onStatusChanged
signal handler:
Loader3D { id : loader onStatusChanged : if ( loader . status == Loader3D . Ready ) console . log ( 'Loaded' ) }
Text { text: loader.status == Loader3D.Ready ? 'Loaded' : 'Not loaded' }
Note that if the source is a local file, the status will initially be Ready (or Error). While there will be no onStatusChanged signal in that case, the onLoaded will still be invoked.
另请参阅 progress .
loaded () |
此信号被发射当
status
becomes
Loader3D.Ready
, or on successful initial load.
相应处理程序是
onLoaded
.
注意:
相应处理程序是
onLoaded
.
object setSource ( url source , object properties ) |
Creates an object instance of the given source component that will have the given properties 。 properties argument is optional. The instance will be accessible via the item property once loading and instantiation is complete.
若
active
特性为
false
at the time when this function is called, the given
source
component will not be loaded but the
source
and initial
properties
will be cached. When the loader is made
active
, an instance of the
source
component will be created with the initial
properties
set.
Setting the initial property values of an instance of a component in this manner will not trigger any associated 行为 s.
Note that the cached properties will be cleared if the source or sourceComponent is changed after calling this function but prior to setting the loader active .