Skip to content

Fix bug arising from PyQt4 where QtGui.qApp is not initialized to None #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

quornian
Copy link

For example, in this first case we have what looks like a QApplication
object, but it is not really there and will cause problems later.

$ python -c 'from PyQt4 import QtGui; print QtGui.qApp'
<PyQt4.QtGui.QApplication object at 0x7f2f884776b0>

$ python -c 'from PySide import QtGui; print QtGui.qApp'
None

Instead we can use QtGui.QApplication.instance(), which always works and
is documented in PySide to return the same as QtGui.qApp anyway.

quornian and others added 2 commits March 28, 2017 18:19
For example, in this first case we have what looks like a QApplication
object, but it is not really there and will cause problems later.

$ python -c 'from PyQt4 import QtGui; print QtGui.qApp'
<PyQt4.QtGui.QApplication object at 0x7f2f884776b0>

$ python -c 'from PySide import QtGui; print QtGui.qApp'
None

Instead we can use QtGui.QApplication.instance(), which always works and
is documented in PySide to return the same as QtGui.qApp anyway.
@quornian
Copy link
Author

Hi @manneohrstrom. Is there any chance this can be merged?

To add more context, the code added by the two commits ac2ef1b and ca9059d makes use of QGui.qApp, which is not set to None in PyQt4 at startup (it's some uninitialized QApplication struct). In PySide it all works fine. Using QtGui.QApplication.instance() on the other hand, always works.

The problem apparently exists in PyQt5 too (with a much better explanation):
https://stackoverflow.com/a/40405396

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant