title: Using QTimer.singleShot correctly
body: <p>I have the following PySide application, where the intended functionality is to have the text of the <code>number_button</code> be updated every 5 seconds, counting from 0 to 9 once the <code>start_button</code> has been pressed.</p>
  
  <pre><code>
  import sys
  from PySide import QtGui, QtCore
  
  class Example(QtGui.QWidget):
  
      def __init__(self, parent=None):
          super(Example, self).__init__(parent)
  
          self.app_layout = QtGui.QVBoxLayout()
          self.setLayout(self.app_layout)
  
          self.setGeometry(300, 300, 50, 50)
  
          self.count_to = 10
          self.delay = 5000
  
          self.timer = QtCore.QTimer(self)
          self.timer.setSingleShot(True)
  
          # start button
          start_button = QtGui.QPushButton()
          start_button.setText('START')
          start_button.clicked.connect(self.startCount)
          self.app_layout.addWidget(start_button)
  
          # number button
          self.number_button = QtGui.QPushButton()
          self.number_button.setText('0')
          self.app_layout.addWidget(self.number_button)
  
  
  
      def startCount(self):
  
          def updateButtonCount():
              self.number_button.setText("%s" % count)
  
          for count in range(0, self.count_to):
              self.timer.singleShot(self.delay, updateButtonCount)
  
  
  def main():
  
      app = QtGui.QApplication(sys.argv)
      example = Example()
      example.show()
      sys.exit(app.exec_())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>However, this results in a <code>9</code> appearing after 6 seconds without the intermediate numbers showing at all. I'm pretty sure that the problem is that while the <code>.singleShot</code> is running, <code>count</code> has already been incremented to its maximum value (<code>9</code>).</p>
  
  <p>I can think of a few hack to make this work as intended, but I'd like to fix it in the most effective and appropriate way.</p>