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

"Cannot read property ... of null" when exiting QML app - QmlElement object lifetime

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.5.2
    • PySide
    • None

      When instantiating a QML element implemented in Python, the object lifetime is shorter than the object lifetime of QML elements defined in C++ or QML leading to `Cannot read property ... of null` errors on application exit.

       

      I've attached 2 minimal examples, one using PySide6 and one using Qt/C++ to demonstrate the problem. The PySide6 example throws the error `main.qml:23: TypeError: Cannot read property 'foo' of null` on application exit, where the C++ application just works.

       

      A workaround is to use defensive coding strategies e.g. nullish coalescing and optional chaining, but that adds unnecessary code compared to the C++ implementation.

        1. object_lifetime_pyside6.zip
          1 kB
          Alex Roessler
        2. pyside2431.zip
          4 kB
          Friedemann Kleint
        3. qt6_qml_element_lifetime_cpp.zip
          5 kB
          Alex Roessler
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            machinekoder Alex Roessler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes