QScopeGuard Class
template <typename F> class QScopeGuard
The QScopeGuard class calls a function when it goes out of scope. More…
| Header | #include <QScopeGuard> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QScopeGuard(F &&f) | |
| QScopeGuard(const F &f) | |
| QScopeGuard(QScopeGuard &&o) | |
| ~QScopeGuard() | |
| void | dismiss() |
Detailed Description
Use qScopeGuard() to create a guard from a callable. The callable runs when the guard is destroyed unless dismiss() was called.
auto guard = qScopeGuard([&] { file.close(); });
See also QScopedValueRollback and QSignalBlocker.
Differences from Qt
None.
Member Function Documentation
QScopeGuard::QScopeGuard(F &&f)
Constructs a guard that calls f on destruction.
QScopeGuard::QScopeGuard(const F &f)
This is an overloaded function.
Constructs a guard that calls a copy of f on destruction.
QScopeGuard::QScopeGuard(QScopeGuard &&o)
Move-constructs a guard from o. The moved-from guard no longer calls its function.
QScopeGuard::~QScopeGuard()
Calls the function unless the guard was dismissed.
void QScopeGuard::dismiss()
Dismisses the guard so that the function is not called on destruction.