Search code examples
pythonpysideqapplication

Find out if app was already initialized?


I wanted to spawn a QWebKit instance in PySide and quickly got a segmentation fault - I forgot to set up an instance of QApplication. Since SIGSEGV is not a good failure mode, is there a way to catch that and throw an exception instead?


Solution

  • The QCoreApplication class (which QApplication inherits), has the static method instance() which allows you to check this:

    if QApplication.instance() is not None:
        # do stuff..
    else:
        raise RuntimeError('no application object')