QQmlIncubationController Class
QQmlIncubationController のインスタンスは、QQmlIncubators の進行を制御します。詳細...
| ヘッダー: | #include <QQmlIncubationController> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) 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) |
詳細な説明
非同期動作を実現し、アプリケーションのカクつきやフリーズを防ぐため、QQmlIncubators オブジェクトの作成処理は、アプリケーションのアイドル時間中にのみ実行される必要があります。QQmlIncubationController を使用することで、アプリケーションはこの処理がいつ、どのくらいの頻度で、どのくらいの期間行われるかを正確に制御できます。
QQmlIncubationController を継承したインスタンスを作成し、QQmlEngine::setIncubationController() メソッドを呼び出して、QQmlEngine に設定する必要があります。その後、アプリケーションの要件に応じて、QQmlIncubationController::incubateFor() またはQQmlIncubationController::incubateWhile() メソッドを呼び出すことで、処理を制御します。
例えば、以下は、16ミリ秒ごとに最大5ミリ秒の間インキュベーションを行うインキュベーション・コントローラの例です。
class PeriodicIncubationController : public QObject,
public QQmlIncubationController
{
public:
PeriodicIncubationController() {
startTimer(16);
}
protected:
void timerEvent(QTimerEvent *) override {
incubateFor(5);
}
};この例は動作しますが、かなり単純化されています。実際のインキュベーション・コントローラは、アプリケーションに支障をきたさない範囲で、消費するアイドル時間を最大化しようとします。上記のように 5 ミリ秒という固定値を使用すると、一部のフレームではアイドル時間が無駄になり、他のフレームではアプリケーションに支障をきたす可能性があります。
QQuickWindow QQuickView および には、より賢いアルゴリズムを用いてインキュベーションを複数のフレームに分散させるインキュベーション・コントローラがあらかじめ用意されています。自分で作成する必要はほとんどありません。QQuickWidget
メンバ関数のドキュメント
QQmlIncubationController::QQmlIncubationController()
新しいインキュベーションコントローラーを作成します。
QQmlEngine *QQmlIncubationController::engine() const
このインキュベーション・コントローラーが設定されているQQmlEngine を返す。いずれのエンジンにも設定されていない場合は0を返す。
void QQmlIncubationController::incubateFor(int msecs)
msecs 用のオブジェクトをインキュベートするか、インキュベートするオブジェクトがなくなるまで続けます。
void QQmlIncubationController::incubateWhile(std::atomic<bool> *flag, int msecs = 0)
flag が指すアトミックな bool 値が true の間、あるいはインキュベートするオブジェクトがなくなるまで、またはmsecs が 0 でない場合はmsecs まで、オブジェクトをインキュベートします。
通常、このメソッドは、インキュベーションを中断したいときにflag が指す bool を false に設定するスレッドや UNIX シグナルと組み合わせて使用されます。
注: flag の読み取りには、acquire メモリ順序が使用されます。
int QQmlIncubationController::incubatingObjectCount() const
現在インキュベーション中のオブジェクトの数を返します。
[virtual protected] void QQmlIncubationController::incubatingObjectCountChanged(int incubatingObjectCount)
インキュベート中のオブジェクトの数が変化したときに呼び出されます。incubatingObjectCount は、インキュベート中のオブジェクトの新しい数です。
デフォルトの実装では何も行いません。
© 2026 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.