I use following class to automatically set waiting cursor in the beginning of a certain function and reset the cursor when function returns.
class WaitCursorSetter
{
public:
WaitCursorSetter() {QApplication::setOverrideCursor(Qt::WaitCursor);}
virtual ~WaitCursorSetter() {QApplication::restoreOverrideCursor();}
};
I create a local WaitCursorSetter
object when function begins. Since waiting cursor is reset in the destructor of object, I do not have to reset the cursor before each and every return statement in the method since destructor gets called when function returns and object goes out of scope.
If the compiler optimized out the unreferenced WaitCursorSetter
object, this will not work. My problem is, is the compiler allowed to optimize out this object?