Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-124345

QML ObjectModel: Following the documentation for append will lead to app crash

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1: Critical P1: Critical
    • 6.8, 6.9.0 FF
    • 6.7.0
    • None
    • Windows 11 Pro 23H2 / build: 22631.3374
      CPU: Intel Core i7-8750H
      GPU: Intel UHD Graphics 630
      RAM: 16 GB
      Qt Version: 6.7.0 msvc2019_64
    • Windows
    • 7c404391c (dev), 44ccaf1df (6.8), 9a936d174 (dev), b7d9f49ab (6.8), e40e9cbbf (dev)

      The documentation to "append"

      in: https://doc.qt.io/qt-6/qml-qtqml-models-objectmodel.html

      has an example how to use it:

       

      objectModel.append(objectComponent.createObject()) 

      if you follow this, your app will most likely crash sooner or later, because the garbage collector will delete the created object.

       

      Two options:

      1. the documentation is correct and "append" does some "magic" to have the garbage collector not delete the item. Then the "magic" is broken.
      2. the documentation is incomplete. In this case, please add a parent to the createObject in the example. There are two other examples for "get" and "insert" where the parent is also missing.

        For Gerrit Dashboard: QTBUG-124345
        # Subject Branch Project Status CR V

            ulherman Ulf Hermann
            basti_4tiitoo Bastian Wolfgruber
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: