PDA

View Full Version : spontaneous events



onamatic
2nd February 2010, 16:14
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.


void QNotes::closeEvent(QCloseEvent* event)
{
cout << "QNotes::closeEvent" << endl;
cout << "qApp->closingDown() = " << qApp->closingDown() << endl; //always 0
cout << "event->spontaneous() = " << event->spontaneous() << endl; //strange! is 0 on logout, 1 on window close
}


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

Archimedes
2nd February 2010, 17:41
I made the following observation on Windows. When I terminate the task through task manager or press the "x" button it returns true and when the app terminates with a close() it returns false.
Anyway, I think it may has something to do with the signals the OS emits, SIGTERM, SIGKILL and SIGINT and how they make the application close. Not sure though and also curious about what's happening!!

onamatic
4th February 2010, 08:29
When I terminate the task through task manager or press the "x" button it returns true

Thanks for that. It's clearly not consistent behaviour across platforms then. I tried investigating behaviour in response to signals (other than SIGKILL) but they never propagate to a closeEvent. I think I need to work at Session or Application level to do this properly.

Bob