QQmlIncubationController instances drive the progress of QQmlIncubators. 更多...
头: | #include <QQmlIncubationController> |
CMake: |
find_package(Qt6 COMPONENTS Qml REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Qml) |
qmake: | QT += qml |
QQmlIncubationController () | |
QQmlEngine * | engine () const |
void | incubateFor (int msecs ) |
void | incubateWhile (std::atomic<bool> * flag , int msecs = 0) |
int | incubatingObjectCount () const |
virtual void | incubatingObjectCountChanged (int incubatingObjectCount ) |
In order to behave asynchronously and not introduce stutters or freezes in an application, the process of creating objects a QQmlIncubators must be driven only during the application's idle time. QQmlIncubationController allows the application to control exactly when, how often and for how long this processing occurs.
A QQmlIncubationController derived instance should be created and set on a QQmlEngine 通过调用 QQmlEngine::setIncubationController () method. Processing is then controlled by calling the QQmlIncubationController::incubateFor () 或 QQmlIncubationController::incubateWhile () methods as dictated by the application's requirements.
For example, this is an example of a incubation controller that will incubate for a maximum of 5 milliseconds out of every 16 milliseconds.
class PeriodicIncubationController : public QObject, public QQmlIncubationController { public: PeriodicIncubationController() { startTimer(16); } protected: void timerEvent(QTimerEvent *) override { incubateFor(5); } };
Although the previous example would work, it is not optimal. Real world incubation controllers should try and maximize the amount of idle time they consume - rather than a static amount like 5 milliseconds - while not disturbing the application.
Create a new incubation controller.
返回 QQmlEngine this incubation controller is set on, or 0 if it has not been set on any engine.
Incubate objects for msecs , or until there are no more objects to incubate.
[since 5.15]
void
QQmlIncubationController::
incubateWhile
(
std::atomic
<
bool
> *
flag
,
int
msecs
= 0)
Incubate objects while the atomic bool pointed to by flag is true, or until there are no more objects to incubate, or up to msecs if msecs is not zero.
Generally this method is used in conjunction with a thread or a UNIX signal that sets the bool pointed to by flag to false when it wants incubation to be interrupted.
注意: flag is read using acquire memory ordering.
该函数在 Qt 5.15 引入。
Return the number of objects currently incubating.
[virtual protected]
void
QQmlIncubationController::
incubatingObjectCountChanged
(
int
incubatingObjectCount
)
Called when the number of incubating objects changes. incubatingObjectCount is the new number of incubating objects.
默认实现什么都不做。