Results 1 to 3 of 3

Thread: spontaneous events

  1. #1
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default spontaneous events

    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

  2. #2
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: spontaneous events

    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!!
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  3. #3
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: spontaneous events

    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

Similar Threads

  1. Qt...Using Events
    By Peppy in forum Qt Programming
    Replies: 5
    Last Post: 27th December 2009, 09:41
  2. Events
    By T0bi4s in forum Newbie
    Replies: 16
    Last Post: 25th November 2009, 22:09
  3. Events
    By SV in forum Qt Programming
    Replies: 0
    Last Post: 21st May 2008, 08:48
  4. QT Events
    By Sreeja in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2006, 08:25
  5. Events - how to
    By eleanor in forum Newbie
    Replies: 2
    Last Post: 13th November 2006, 07:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.