Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1093

staticMetaObjects disappear when using QApplication.instance()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.13.2
    • 5.13.1
    • PySide
    • None
    • macOS
    • 63e46f6a0a80cda662be9350923a9e080fac7b6f (pyside/pyside-setup/5.13)

    Description

      A standard pattern for initializing QApplication in libraries is to use QApplication.instance() and fall back to explicitly instantiating QApplication() if that returns None. See here for an example from matplotlib.

      When one calls QApplication.instance() without having first created a QApplication, this appears to have the side effect of setting all staticMetaObject attributes to None.

      from PySide2 import QtCore, QtWidgets
      
      print(repr(QtCore.QObject.staticMetaObject))
      
      app = QtWidgets.QApplication.instance()
      print(repr(QtCore.QObject.staticMetaObject))
      
      if app is None:
          app = QtWidgets.QApplication([])
      print(repr(QtCore.QObject.staticMetaObject))
      

       
      I get a result that looks like this:

      <PySide2.QtCore.QMetaObject object at 0x10e5c72c8>
      None
      None
      

      When it should look like this:

      <PySide2.QtCore.QMetaObject object at 0x10e5c72c8>
      <PySide2.QtCore.QMetaObject object at 0x10e5c72c8>
      <PySide2.QtCore.QMetaObject object at 0x10e5c72c8>
      

      Checking for an existing QApplication with QApplication.startingUp() first appears to work OK, but I can't fix all of the third-party libraries to change to that pattern. PyQt4, PyQt5, PySide 1 all seem to be okay with the above pattern.

      Attachments

        Issue Links

          For Gerrit Dashboard: PYSIDE-1093
          # Subject Branch Project Status CR V

          Activity

            People

              ctismer Christian Tismer
              robert.kern@gmail.com Robert Kern
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes