QQmlIncubationController Class
QQmlIncubationController インスタンスは、QQmlIncubator の進捗を管理します。さらに...
ヘッダー | #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 、またはインキュベートするオブジェクトがなくなるまで、msecs が0でない場合はmsecs まで、指されたアトミック・ブールがtrueの間オブジェクトをインキュベートする。
一般的にこのメソッドは、インキュベーションを中断させたいときにflag が指すブールをfalseに設定するスレッドまたはUNIXシグナルと組み合わせて使用される。
注: flag は、acquire メモリー順序を使用して読み込まれる。
int QQmlIncubationController::incubatingObjectCount() const
現在インキュベートしているオブジェクトの数を返す。
[virtual protected]
void QQmlIncubationController::incubatingObjectCountChanged(int incubatingObjectCount)
孵卵しているオブジェクトの数が変わったときに呼び出される。incubatingObjectCount は新しい孵卵しているオブジェクトの数。
デフォルトの実装では何もしない。
© 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.