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

Brian Kelley kelley at eyesopen.com
Mon Mar 2 18:47:59 GMT 2009


When you start another mainwindow (or top level widget for that matter) you don't need to call exec_ or make another QApplication.

The way I normally import things like this is the following:

Foo.py

class MainWindow()...
...

def Start():
    m = MainWindow()
    m.show()

if __name__ == "__main__":
  import sys
  app = QApplication(sys.argv)
  Start()
  app.exec_()


To start the application from the command line,

python Foo.py

And to load it from another modele, Bar.

import Foo
Foo.Start()

Brian

On 3/2/09 1:38 PM, "Brent Villalobos" <Brent.Villalobos at pdi.dreamworks.com> wrote:

I have a pyqt application that imports and runs another pyqt
application.  I am not launching the second application in its own
process, but I'm just relying on python's module importing
architecture.  Both applications seems to run fine without any problems,
but I'm seeing this warning message:
    QCoreApplication::exec: The event loop is already running

While everything seems to run fine I feel like I'm doing something wrong
and I will eventually be bitten by some odd side effect.  Are these
fears warranted?  I know that the Qt documentation says that you should
only have one QApplication instance so is this just warning and Qt is
doing the right thing "under the hood?"

If this will create problems, can you provide some suggestions on what I
should do differently?  I want to avoid launching a second process if
possible.  Is it possible for one QApplication instance to manage
multiple gui applications without problems?

Finally, if there is no problem is there a way I can suppress that
warning so that users don't freak out?  Thanks.
-Brent
_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090302/59a120e5/attachment.html


More information about the PyQt mailing list