织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

QQmlIncubator 欧博注册Class

时间:2025-10-20 12:28来源: 作者:admin 点击: 9 次
The QQmlIncubator class allows QML objects to be created asynchronously.

The QQmlIncubator class allows QML objects to be created asynchronously.

Header:   #include <QQmlIncubator>  
CMake:   find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
 
qmake:   QT += qml  

Public Types

enum   { Asynchronous, AsynchronousIfNested, Synchronous }  
enum   { Null, Ready, Loading, Error }  

Public Functions

  (QQmlIncubator::IncubationMode mode = Asynchronous)  
void   ()  
QList<QQmlError>   () const  
void   ()  
QQmlIncubator::IncubationMode   () const  
bool   () const  
bool   () const  
bool   () const  
bool   () const  
QObject *   () const  
void   (const QVariantMap &initialProperties)  
QQmlIncubator::Status   () const  

Protected Functions

virtual void   (QObject *object)  
virtual void   (QQmlIncubator::Status status)  

Detailed Description

Creating QML objects - like delegates in a view, or a new page in an application - can take a noticeable amount of time, especially on resource constrained mobile devices. When an application uses () directly, the QML object instance is created synchronously which, depending on the complexity of the object, can cause noticeable pauses or stutters in the application.

The use of QQmlIncubator gives more control over the creation of a QML object, including allowing it to be created asynchronously using application idle time. The following example shows a simple use of QQmlIncubator.

// Initialize the incubator QQmlIncubator incubator; component->create(incubator);

Let the incubator run for a while (normally by returning control to the event loop), then poll it. There are a number of ways to get back to the incubator later. You may want to connect to one of the signals sent by QQuickWindow, or you may want to run a QTimer especially for that. You may also need the object for some specific purpose and poll the incubator when that purpose arises.

// Poll the incubator if (incubator.isReady()) { QObject *object = incubator.object(); // Use created object }

Asynchronous incubators are controlled by a QQmlIncubationController that is set on the QQmlEngine, which lets the engine know when the application is idle and incubating objects should be processed. If an incubation controller is not set on the QQmlEngine, QQmlIncubator creates objects synchronously regardless of the specified . By default, no incubation controller is set. However, QQuickView, QQuickWindow and QQuickWidget all set incubation controllers on their respective QQmlEngines. These incubation controllers space out incubations across multiple frames while the view is being rendered.

QQmlIncubator supports three incubation modes:

Member Type Documentation enum QQmlIncubator::IncubationMode

Specifies the mode the incubator operates in. Regardless of the incubation mode, a QQmlIncubator will behave synchronously if the QQmlEngine does not have a QQmlIncubationController set.

ConstantValueDescription
QQmlIncubator::Asynchronous   0   The object will be created asynchronously.  
QQmlIncubator::AsynchronousIfNested   1   If the object is being created in a context that is already part of an asynchronous creation, this incubator will join that existing incubation and execute asynchronously. The existing incubation will not become Ready until both it and this incubation have completed. Otherwise, the incubation will execute synchronously.  
QQmlIncubator::Synchronous   2   The object will be created synchronously.  

enum QQmlIncubator::Status

Specifies the status of the QQmlIncubator.

ConstantValueDescription
QQmlIncubator::Null   0   Incubation is not in progress. Call () to begin incubating.  
QQmlIncubator::Ready   1   The object is fully created and can be accessed by calling ().  
QQmlIncubator::Loading   2   The object is in the process of being created.  
QQmlIncubator::Error   3   An error occurred. The errors can be access by calling ().  

Member Function Documentation QQmlIncubator::QQmlIncubator( mode = Asynchronous)

Create a new incubator with the specified mode

void QQmlIncubator::clear()

Clears the incubator. Any in-progress incubation is aborted. If the incubator is in the Ready state, the created object is not deleted.

QList<QQmlError> QQmlIncubator::errors() const

Return the list of errors encountered while incubating the object.

void QQmlIncubator::forceCompletion()

Force any in-progress incubation to finish synchronously. Once this call returns, the incubator will not be in the Loading state.

QQmlIncubator::incubationMode() const

Return the incubation mode passed to the QQmlIncubator constructor.

bool QQmlIncubator::isError() const

Returns true if the incubator's () is Error.

bool QQmlIncubator::isLoading() const

Returns true if the incubator's () is Loading.

bool QQmlIncubator::isNull() const

Returns true if the incubator's () is Null.

bool QQmlIncubator::isReady() const

Returns true if the incubator's () is Ready.

QObject *QQmlIncubator::object() const

Return the incubated object if the status is Ready, otherwise 0.

void QQmlIncubator::setInitialProperties(const &initialProperties)

Stores a mapping from property names to initial values, contained in initialProperties, with which the incubated component will be initialized.

See also .

[virtual protected] void QQmlIncubator::setInitialState(QObject *object)

Called after the object is first created, but before complex property bindings are evaluated and, if applicable, () is called. This is equivalent to the point between () and (), and can be used to assign initial values to the object's properties.

The default implementation does nothing.

Note: Simple bindings such as numeric literals are evaluated before setInitialState() is called. The categorization of bindings into simple and complex ones is intentionally unspecified and may change between versions of Qt and depending on whether and how you are using qmlcachegen. You should not rely on any particular binding to be evaluated either before or after setInitialState() is called. For example, a constant expression like MyType.EnumValue may be recognized as such at compile time or deferred to be executed as binding. The same holds for constant expressions like -(5) or "a" + " constant string".

QQmlIncubator::status() const

Return the current status of the incubator.

[virtual protected] void QQmlIncubator::statusChanged( status)

Called when the status of the incubator changes. status is the new status.

The default implementation does nothing.

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

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-11-04 11:11 最后登录:2025-11-04 11:11
栏目列表
推荐内容