I'm using QT 4.6.0 + Fedora 2.6.30.10-105.2.4.fc11.x86_64

This is a snippet from my QMainWindow class called QNotes in which I'm trying to detect a user logout or system shutdown as opposed to the user just closing the window.

Qt Code:
  1. void QNotes::closeEvent(QCloseEvent* event)
  2. {
  3. cout << "QNotes::closeEvent" << endl;
  4. cout << "qApp->closingDown() = " << qApp->closingDown() << endl; //always 0
  5. cout << "event->spontaneous() = " << event->spontaneous() << endl; //strange! is 0 on logout, 1 on window close
  6. }
To copy to clipboard, switch view to plain text mode 


qApp->closingDown() always returns 0. Presumably because the application is not actually being destroyed when closeEvent is called.

event->spontaneous() returns 0 if user is logging out or system is shutting down. Otherwise, it returns 1. This is fine, the rest of my code works perfectly. But surely the logic is inverted?
The doc. for QEvent::spontaneous says "Returns true if the event originated outside the application (a system event); otherwise returns false." I would have thought a logout or shutdown would be an external event and should return 1?

Any enlightenment gratefully received.

Bob