Skip to content
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

BUG : make qApp global before using it #3381

Merged
merged 1 commit into from Aug 18, 2014

Conversation

tacaswell
Copy link
Member

Make qApp global in backend_qt5.py before using it.

This silences a warning.

I don't think this change requires a new RC.

closes #3379

Make qApp global in backend_qt5.py before using it.

This silences a warning.
@tacaswell tacaswell added this to the v1.4.0 milestone Aug 18, 2014
efiring added a commit that referenced this pull request Aug 18, 2014
BUG : make qApp global before using it
@efiring efiring merged commit 6e978d7 into matplotlib:v1.4.x Aug 18, 2014
@tacaswell tacaswell deleted the qapp_global_fix branch August 18, 2014 03:19
@ezust
Copy link

ezust commented Aug 19, 2014

I am confused by this. "qApp" is actually something that comes from PyQt5.QtCore.
Are you defining it to be something different in matplotlib? Why not just add a
"from PyQt5.QtCore import qApp" in the places you need it?

@jenshnielsen
Copy link
Member

Not in this case. Look a few lines below it is initialised either as QtWidgets.QApplication.instance()
or as QtWidgets.QApplication([str(" ")])

@jenshnielsen
Copy link
Member

In addition I can't see it in QtCore

In [4]: from PyQt5.QtCore import qApp
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-333c82883eb3> in <module>()
----> 1 from PyQt5.QtCore import qApp

ImportError: cannot import name 'qApp'

There is a qAbs

@ezust
Copy link

ezust commented Aug 19, 2014

Sorry, I meant

from PyQt5.Qt import qApp

On Tue, Aug 19, 2014 at 8:48 AM, Jens H Nielsen notifications@github.com
wrote:

In addition I can't see it in QtCore

In [4]: from PyQt5.QtCore import qApp---------------------------------------------------------------------------ImportError Traceback (most recent call last) in ()----> 1 from PyQt5.QtCore import qApp
ImportError: cannot import name 'qApp'

There is a qAbs


Reply to this email directly or view it on GitHub
#3381 (comment)
.

@ezust
Copy link

ezust commented Aug 19, 2014

Or

from PyQt5.QtWidgets import qApp

Wrong module, sorry.

@efiring
Copy link
Member

efiring commented Aug 19, 2014

To avoid this name confusion, we should not be using qApp as a variable name.

@efiring
Copy link
Member

efiring commented Aug 19, 2014

@ezust, what is the right way to handle this? At the C++ level, qApp is described as a Macro; what is it in PyQt5? How is it initialized?

@jenshnielsen
Copy link
Member

The only reference I could find in PyQT docs is this http://pyqt.sourceforge.net/Docs/PyQt4/qtgui.html#qApp-var

(In PyQT4 it was in qtgui) But it is not very informative

@ezust
Copy link

ezust commented Aug 19, 2014

It looks like qApp is initialized by Qt in a very similar way to how you
guys are initializing it (QtWidgets.QApplication.instance()), so I might be
making a big deal out of nothing.
Before, I just was looking at the patch all by itself and it made no sense
to me that you would need to declare another global variable for it if you
can just import it.

On Tue, Aug 19, 2014 at 10:29 AM, Eric Firing notifications@github.com
wrote:

@ezust https://github.com/ezust, what is the right way to handle this?
At the C++ level, qApp is described as a Macro; what is it in PyQt5? How is
it initialized?


Reply to this email directly or view it on GitHub
#3381 (comment)
.

@ezust
Copy link

ezust commented Aug 19, 2014

The reason it is a macro in c++ is so it can return a QCoreApplication if
you are only using QtCore, and a QGuiApplication if you are only using
QtGui and a QApplication if you are using QWidget, depending on which
header file you included.

@tacaswell
Copy link
Member Author

My understanding of this was that there can only be one running QApplication in the process. QWidgets.QApplication.instance() will either return a reference to the currently running application (not sure how it is done at the c++ level, but I assume one of those macros) or None. If it's None, we start up the application so that we can safely make the gui windows (if we don't have an QApp starting Painter throws errors).

For convince we store the the reference in a module-level global.

@efiring
Copy link
Member

efiring commented Aug 19, 2014

@tacaswell, I think your understanding is correct, and the existing code is OK. I suspect that the same thing could be accomplished using the imported qApp, but it would take some investigation to figure out how to do it (e.g., how is it initialized upon import?). This might be worth sorting out, but if the present code works, then changing it is not high priority.

The present organization, in which backend_qt4 imports _create_qApp() and other things from backend_qt5 seems a little odd; but it all went through review before being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants