java.lang.Object
io.qt.core.QScopeGuard
- All Implemented Interfaces:
AutoCloseable
QScopeGuard is a class of which the sole purpose is to run the function f
at the end of a try-with-resource block.
This is useful for guaranteeing your cleanup code is executed, whether the function is exited normally,
exited early by a return statement, or exited by an exception.
See QScopeGuard.
Example:
QIODevice device = ...
try(var guard = new QScopeGuard(device::close)){
if(!device.open())
guard.dismiss();
else
device.write(...);
}
-
Constructor Summary
ConstructorDescriptionQScopeGuard
(Runnable function) Create a scope guard that will executefunction
at the end of the scope. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
dismiss()
Disarms the scope guard, so that the function F will not be called at the end of the scope.static QScopeGuard
qScopeGuard
(Runnable runnable) The qScopeGuard function can be used to call a function at the end of the scope.
-
Constructor Details
-
QScopeGuard
Create a scope guard that will executefunction
at the end of the scope.- Parameters:
function
- runnable to be executed
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
-
dismiss
Disarms the scope guard, so that the function F will not be called at the end of the scope. -
qScopeGuard
The qScopeGuard function can be used to call a function at the end of the scope.
-