QScopedValueRollback Class

template <typename T> class QScopedValueRollback

QScopedValueRollbackクラスは、変数が破棄されたときに、その変数を以前の値にリセットします。詳細...

ヘッダー #include <QScopedValueRollback>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

パブリック関数

詳細説明

QScopedValueRollbackクラスは、try-catchブロックを記述することなく、例外がスローされたときに状態を戻すために使用できます。

また、再入可能性ガードなど、一時的に設定された変数を管理するためにも使用できます。このクラスを使うことで、関数が正常終了しても、return文で早期終了しても、例外で終了しても、変数はリセットされます。

このテンプレートは、代入をサポートする型でのみインスタンス化できます。

QScopedPointer およびQScopeGuardも参照してください

メンバ関数のドキュメント

[explicit constexpr] QScopedValueRollback::QScopedValueRollback(T &var)

破壊時に戻すために、var の前の値を内部に保存する。

[explicit constexpr] QScopedValueRollback::QScopedValueRollback(T &var, T value)

varにvalue を代入し、var の前の値を内部的に保存する。

[constexpr] QScopedValueRollback::~QScopedValueRollback()

前の値を管理変数に代入する。これは、構築時、または最後にcommit() を呼び出したときの値である。

[constexpr] void QScopedValueRollback::commit()

管理変数の前回値を現在値に更新する。

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