[PyQt] QCoreApplication::exec: The event loop is already running

Giovanni Bajo rasky at develer.com
Tue Mar 3 00:25:43 GMT 2009


On lun, 2009-03-02 at 11:12 -0800, Brent Villalobos wrote:
> Brian Kelley wrote:
> > When you start another mainwindow (or top level widget for that 
> > matter) you don’t need to call exec_ or make another QApplication.
> 
> That's good. Along those same lines does Qt provide a way of querying 
> whether a QApplication loop is already running so you can avoid making a 
> new one?

Why don't you simply reorganize the code a bit so to provide another
entry point which doesn't create your application? Any PyQt application
should have a main no more complicated than this:

if __name__ == "__main__":
    app = QApplication([])
    w = MySuperMainWidget()
    w.show()
    app.exec_()

just add a function like this:

    def entry():
         global w
         w = MySuperMainWidget()
         w.show()

and you're done with it.
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com




More information about the PyQt mailing list