I need to know when a window is restored or maximized. When this state-change happens, I need to take an action. I need to be careful however that this action only occurs once per state-change. I have the following code:

Qt Code:
  1. void TextArea::changeEvent(QEvent* event)
  2. {
  3. if (event->type() == QEvent::WindowStateChange)
  4. {
  5. if (static_cast<QWindowStateChangeEvent*>(event)->oldState() == windowState())
  6. {
  7. return;
  8. }
  9. if (isMaximized())
  10. {
  11.  
  12. }
  13. else
  14. {
  15.  
  16. }
  17. }
  18. QWidget::changeEvent(event);
  19. }
To copy to clipboard, switch view to plain text mode 

Even with the preceding code, the action is firing twice with the old-state being 0 and new state being 2. Is there any way to ensure that this fires only once?