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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…