Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

C++ object destructor is not invoked when QML item is destroyed



  • Hello,

    I have a subclass of QQuickItem that I use in a qml view. I've noticed that when I destroy the qml view, all qml-based children are destroyed but for c++ objects it's not a case. When I close the whole application, destructors for these objects are invoked. Is it possible to do something with that?

    Thanks a lot,
    Maksim



  • Hmm, you can call delete for the objects in the destructor of your QQuickItem



  • Ricardo, frankly I didn't get that. I have a class lets say MyNiceChart that extends QQuickItem. I registerd this new type and use it in qml

    @
    Rectangle {
    id : somePanel

     MyNiceChart {
     }
    
     Rectangle {
          id : antoherItem
     }     
    

    }
    @

    So when I don't need somePanel anymore I destroy it : somePanel.destroy() and I noticed that
    anotherItem will be destroyed as well during this operation but destructor of MyNiceChart is not invoked. Do you suggest to invoke MyNiceChart destructor manually?




Log in to reply