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

QMainWindow collects children when set visible, semantics unclear

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 6.7.0, 6.8.2
    • PySide
    • None
    • Linux/X11

    Description

      One of our tests started failing between Qt/PySide 6.6 and 6.7/6.8. It raises the error `RuntimeError: Internal C++ object (FigureCanvasQTAgg) already deleted`. This appears to be triggered by changing the visibility of a subclass of QMainWindow. I am aware that QMainWindow takes ownership of it's children and garbage collects them under certain conditions. However, I found this specific instance unintuitive, and I think the historical semantics are more clear. In PySide 6.7 and newer, setting the visibility of the main window to False and then True temporarily, causes it to collect its children.  I've created a minimal example that can be run with `pytest minimal_example.py`. I also noticed just now that the first setVIsible can be commented out and with only `setVisible(True)` it still triggers this behavior still, Removing this line, even with `setVIsible(False)` in place makes the test pass.  Since this changed pretty recently and the behavior is at least to me unexpected I was wondering if this was maybe a bug?

      I was unable to recreate it with the stripped down objects, but I found that in the actual test we could set the parent to a widget in global scope and it would resolve the issue as well. I assume the way we use QMainWindow is at least a minor antipattern, but I think there are use cases where a user may want to temporarily hide the main window the way we are, and afaict that isn't possible in the latest version of PySide. If this behavior is intended, is there an idiomatic way to ensure that objects have the correct lifetime?

      minimal_example.py

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            evarady Ezra Varady
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes