<nitpick> According to PEP-8, don't compare using == to singletons:
http://www.python.org/dev/peps/pep-0008/#programming-recommendations """Comparisons to singletons like None should always be done with is or is not, never the equality operators.""" app = QApplication.instance() if app is None: app = QApplication(sys.argv) </nitpick> Blair On 05/23/2012 02:19 PM, Jason Augustyn wrote: > Thanks, Nathan, after poking around a bit more I found a similar solution: > > app = QApplication.instance() > if app == None: > app = QApplication(sys.argv) > > This works! > > > > On Wed, May 23, 2012 at 5:03 PM, Nathan Smith <[email protected] > <mailto:[email protected]>> wrote: > > Hi Jason, > > PySide only supports creating a single persistent instance of > QApplication. This singleton exists forever and cannot be deleted. > If you have a function that tries to create a QApplication, then I > recommend placing that creation inside of a try/except block: > > try: > app = QtGui.QApplication(sys.argv) > except RuntimeError: > app = QtCore.QCoreApplication.instance() > > > This will either create a new QApplication instance if one does not > exist, or return the current QApplication instance if one already > does exist. > > Nathan > > On Wed, May 23, 2012 at 3:21 PM, Jason Augustyn > <[email protected] <mailto:[email protected]>> wrote: > > Hi all, I am new to using PySide and have been working through > the novice tutorials, which are great. One problem - I cannot > re-run a script without exiting the Python shell altogether. > Re-running gives the RuntimeError: A QApplication instance > already exists. > > I have searched for a solution and found an old bug tracker > ticket from someone with a similar problem. The suggested > solution was to upgrade to PySide 1.0.4 and the ticket was > marked as invalid. Obviously that doesn;t work, as I'm running > the newest version of PySide and still have the problem. Any > suggestions? I am using IPython on a Mac OSX 10.7. > > Thanks! > > Jason > > _______________________________________________ > PySide mailing list > [email protected] <mailto:[email protected]> > http://lists.qt-project.org/mailman/listinfo/pyside > > > > > > _______________________________________________ > PySide mailing list > [email protected] > http://lists.qt-project.org/mailman/listinfo/pyside _______________________________________________ PySide mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/pyside
