title: What is the proper way to quit an application in pyqt4?
body: <p>I am studying pyqt4 and is following an tutorial on the internet. Somehow the quit line in the example code doesn't work:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  """
  ZetCode PyQt4 tutorial 
  
  This program creates a quit
  button. When we press the button,
  the application terminates. 
  
  author: Jan Bodnar
  website: zetcode.com 
  last edited: October 2011
  """
  
  import sys
  from PyQt4 import QtGui, QtCore
  
  
  class Example(QtGui.QWidget):
  
      def __init__(self):
          super(Example, self).__init__()
  
          self.initUI()
  
      def initUI(self):               
  
          qbtn = QtGui.QPushButton('Quit', self)
          qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
          qbtn.resize(qbtn.sizeHint())
          qbtn.move(50, 50)       
  
          self.setGeometry(300, 300, 250, 150)
          self.setWindowTitle('Quit button')    
          self.show()
  
  def main():
  
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>When I pressed the X button or the Quit button in the gui, the console prompted some error:</p>
  
  <pre><code>Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32
  Type "copyright", "credits" or "license()" for more information.
  &gt;&gt;&gt; ================================ RESTART ================================
  &gt;&gt;&gt; 
  Traceback (most recent call last):
    File "D:\Raymond\Programming Practice\python\gui_qt\lesson1_basic\gui_quit.py", line 46, in &lt;module&gt;
      main()
    File "D:\Raymond\Programming Practice\python\gui_qt\lesson1_basic\gui_quit.py", line 42, in main
      sys.exit(app.exec())
  SystemExit: 0
  </code></pre>
  
  <p>I fixed the code by replacing the line</p>
  
  <pre><code>sys.exit(app.exec())
  </code></pre>
  
  <p>with the this line:</p>
  
  <pre><code>return app.exec()
  </code></pre>
  
  <p>Then the application exit gracefully. However I am not sure if this method has any disadvantage because it just return the status.</p>