Skip to content

Issue with creating QApplication in QT backend #15100

Closed

Description

@macdems

In the file backend_qt5.py in line 126 a new QApplication object is created. However, the passed argument is a list with a binary string. This causes PySide2 to print ugly

QSettings::value: Empty key passed
QSettings::value: Empty key passed

Correctly, the string should be passed, which will make the warning go away.

To resolve this issue, please replace

qApp = QtWidgets.QApplication([b"matplotlib"])

to this

qApp = QtWidgets.QApplication(["matplotlib"])

Activity

  1. ImportanceOfBeingErnest commented on Aug 22, 2019

    @ImportanceOfBeingErnest
    Member

    The confusing bit here is that the b was introduced in #9169 to actually fix pyside.

  2. added this to the v3.3.0 milestone on Aug 22, 2019
  3. tacaswell commented on Aug 22, 2019

    @tacaswell
    Member

    I guess we need some conditional logic on what to pass as the name based on which Qt wrapper we are using. Want to take a crack at that @macdems ?

  4. macdems commented on Aug 23, 2019

    @macdems
    ContributorAuthor

    I have investigated the issue and it seems that for #9162, the critical commit is fb6fa1d. You can safely revert 52eb8b8 and the bug #9162 is still not present.

  5. tacaswell commented on Aug 23, 2019

    @tacaswell
    Member

    52eb8b8 is addressing #9162 (comment) which per https://bugreports.qt.io/browse/PYSIDE-75 seems to be fixed in pyside2, but we still support (but not not test super well) pyside + qt4 so I do not think we can revert that commit.

  6. macdems commented on Aug 23, 2019

    @macdems
    ContributorAuthor

    Ok, but the problem only happens in Python2 (see the u"Hello" in https://bugreports.qt.io/browse/PYSIDE-75). It is not present in Python3. And in Python2 , the string withou the b in the beginning is not a unicode, so you can safely remove it. Check that the following code works with both Python versions:

    from PySide.QtGui import QApplication
    QApplication(["Hello"])

    Passing b"matplotlib" to QApplication in Python3, passes bytes, not string, which is incorrect.

  7. anntzer commented on Aug 23, 2019

    @anntzer
    Contributor

    The last commit to pyside dates back to October 2015 (https://github.com/pyside/PySide) which is more than a year earlier than the release of the oldest supported Python (Py 3.6, December 2016 https://www.python.org/downloads/release/python-360/). Given that we can't even test it properly, I think it's time to call it quits on pyside(1)...

  8. macdems commented on Aug 23, 2019

    @macdems
    ContributorAuthor

    I suggest that you simply change b"matplotlib" to `"matplotlib" and check that it works in any case.

    However, if you insist on some verification, you can make the line look like this:

    app = QtWidgets.QApplication(["matplotlib" if isinstance("mpl", str) else b"matplotlib"])

    This will guard you against the unicode literals (from __future__ import unicode_literals), although I do not see them used in backend_qt5.py.

  9. tacaswell commented on Aug 23, 2019

    @tacaswell
    Member

    We do not support python2 so that conditional will always be True.

    I think the question we need answered is: Is there a version of pyside that works with py36 and requires a bytes object as input?

    Trading suppressing a warning for a segfault seems like a bad deal ;)

  10. anntzer commented on Aug 23, 2019

    @anntzer
    Contributor

    Both conda-forge and gohlke have pyside for Py3.6 (https://anaconda.org/conda-forge/pyside/files, https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyside), but not Py3.7. So I guess it may be reasonable to drop support for it at the same time as we drop support for Py3.6, which according to my calculations should be around mpl3.3.

  11. macdems commented on Aug 24, 2019

    @macdems
    ContributorAuthor

    I think the question we need answered is: Is there a version of pyside that works with py36 and requires a bytes object as input?

    There is no such version to my knowledge. According to my tests PYSIDE-75 is only Python2 issue. Actually you must always pass an str object and in Python2 b"matplotlib" is such an object. In Python3 it is not.

    Actually, in Python3, passing b"matplotlib" is a bug. In both PySide and PySide2 result in the app.arguments() returning [''], which is not correct (it should return ['matplotlib'] and this is what both PyQt4 and PyQt5 do). I don't think this really matters in this particular use case, but it is not correct anyway.

    If you insist on some workaround (which I believe should not be done), you can always do:

    app = QtWidgets.QApplication([b"matplotlib" if 'PySide' in sys.modules else "matplotlib"])
  12. tacaswell commented on Aug 24, 2019

    @tacaswell
    Member

    Great, if this is a python2 only work around, then 👍 on that change. Could you open a PR?

  13. modified the milestones: v3.3.0, v3.2.0 on Aug 24, 2019
  14. added a commit that references this issue on Aug 26, 2019
  15. tacaswell commented on Aug 26, 2019

    @tacaswell
    Member

    closed by #15122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions