[PyQt] QTimer.singleShot

Baz Walter bazwal at ftml.net
Thu Oct 8 19:09:23 BST 2009


Jason H wrote:
> I have a GUI application and I want to trigger an event after my GUI starts:
> if __name__=="__main__":
>     a = QApplication(sys.argv)
>     
>     m=Main(False)
>     m.show()
>     a.exec_()
>     
> I put "QTimer.singleShot(0, self.start)"
> after the m __init__ialization, both in the class, and I also tried it after m.show() but the console just floods with:
> 
> QCoreApplication::exec: The event loop is already running
> QCoreApplication::exec: The event loop is already running
> QCoreApplication::exec: The event loop is already running
> QCoreApplication::exec: The event loop is already running
> 
> What do I have to do to get my GUI started and using the existing event loop?

it's difficult to be certain what the problem is from what you've posted 
as you've left out all the relevant code.

how does your actual code differ from the working example below:

import sys
from PyQt4 import QtCore, QtGui

class MainWindow(QtGui.QMainWindow):
     def __init__(self):
         QtGui.QMainWindow.__init__(self)
         QtCore.QTimer.singleShot(0, self.start)

     def start(self):
         print 'start'

if __name__ == "__main__":

     app = QtGui.QApplication(sys.argv)
     mw = MainWindow()
     mw.show()
     sys.exit(app.exec_())


More information about the PyQt mailing list