QScopedValueRollback Class
The QScopedValueRollback class resets a variable to its previous value on destruction. More...
Header: | #include <QScopedValueRollback> |
qmake: | QT += core |
Since: | Qt 4.8 |
Public Functions
QScopedValueRollback(T &var) | |
QScopedValueRollback(T &var, T value) | |
~QScopedValueRollback() | |
void | commit() |
Detailed Description
The QScopedValueRollback class resets a variable to its previous value on destruction.
The QScopedValueRollback class can be used to revert state when an exception is thrown without needing to write try-catch blocks.
It can also be used to manage variables that are temporarily set, such as reentrancy guards. By using this class, the variable will be reset whether the function is exited normally, exited early by a return statement, or exited by an exception.
The template can only be instantiated with a type that supports assignment.
See also QScopedPointer.
Member Function Documentation
QScopedValueRollback::QScopedValueRollback(T &var)
Default constructs an instance of QScopedValueRollback.
QScopedValueRollback::QScopedValueRollback(T &var, T value)
Default constructs an instance of QScopedValueRollback.
QScopedValueRollback::~QScopedValueRollback()
Destroys the instance of QScopedValueRollback.