Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Order of signals on application quitting
QtWS25 Last Chance

Order of signals on application quitting

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 8.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fluca1978
    wrote on last edited by
    #1

    In my main window I defined an action to quit the application, and I've overriden the closeEvent method to handle some before-exiting behaviour. Now, it is correct to assume that the following:

    @
    connect( actionQuit,
    SIGNAL(triggered()),
    this,
    SLOT(close()) );
    connect( actionQuit,
    SIGNAL(triggered()),
    qApp,
    SLOT(quit()) );
    @

    will always call issue the QCloseEvent and only after exits the application?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      issue yes, but handle no.

      The point is, that the close event will be pushed in the event queue, directly after which the call to qApp->quit is made. That means that whatever happens in qApp->quit is executed before the QCloseEvent is handled, as the application has not returned to the eventloop yet. That would only happen if all the connected signals have been invoked, but in this case, qApp->quit just might get rid of the entire event queue or something like that.

      What you could try to do, is make your second connect a queuedConnection. That way, it will be handled only when the eventloop is running again, and the event queue will already have the QCloseEvent on it by then.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fluca1978
        wrote on last edited by
        #3

        And what if I leave the qApp.quit slot connected and perform the pre-exit behaviour in the main window destructor? I guess qApp will free memory on exit, so the destructor will be called anyway, right? Moreover I could set the Qt::WA_deleteOnclose attribute of the main window to force the deletion when the window is closed. Could it work?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          I think the behaviour is partly undocumented, but it cannot be changed:

          the slots will be invoked in that order (first close(), then quit());

          close() will post a QCloseEvent;

          quit() will tell the event loop to exit.

          edited -- I stand up corrected, better avoid to leave false statements around

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            The point here is if the event loop is flushed or not, that is if all events are delivered or the application simply aborts. The "exit":http://doc.qt.nokia.com/4.7/qcoreapplication.html#exit documentation says that

            bq. After this function has been called, the application leaves the main event loop and returns from the call to exec()

            and if I get it right, it is not safe to assume the event queue will be flushed.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              p91paul
              wrote on last edited by
              #6

              [quote author="fluca1978" date="1317204693"]And what if I leave the qApp.quit slot connected and perform the pre-exit behaviour in the main window destructor? I guess qApp will free memory on exit, so the destructor will be called anyway, right? Moreover I could set the Qt::WA_deleteOnclose attribute of the main window to force the deletion when the window is closed. Could it work?[/quote]

              I really think this should work. surely the object will be deleted on program exit, and I think each object destructor is called.
              Paolo

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved