title: Is there a way to call a function right before a PyQt application ends?
body: <p>I am collecting usage stats for my applications which include how much each session lasts. However, I can't seem to be able to save this information because None Of the signals I tried yet actually succeeds to call my report_session function. </p>
  
  <p>This are the signals I have already tried:</p>
  
  <ol>
  <li>lastWindowClosed()</li>
  <li>aboutToQuit()</li>
  <li>destroyed()</li>
  </ol>
  
  <p>Either these signals never get emitted or the application does not live long enough after that to run anything else. Here is my main:</p>
  
  <pre><code>app = QtGui.QApplication(sys.argv)
  
  ui = MainWindow()
  ui.app = app
  QtCore.QObject.connect(ui, QtCore.SIGNAL("destroyed()"),  ui.report_session)
  ui.show()
  logger.info('Started!')
  splash.finish(ui)
  
  sys.exit(app.exec_())
  </code></pre>