Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Get notified that object gonna be destroyed

    QML and Qt Quick
    2
    4
    575
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      morte last edited by

      I have QObject-derived class "Banner" exposed to QML as QML_ELEMENT and QML_UNCREATEBLE,
      at QML side i have poroperty of type Banner

      property Banner myBanner: BannerFactory.createBanner()
      

      if later, somewhere in QML i call myBanner.destroy() that will lead to call of Banner destructor ~Banner::Banner(), but is it possible to get notified inside Banner class that object going to be destroyed before destructor is called?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @morte last edited by

        @morte
        Slightly strange request, why should you need to know before destructor is called?

        Anyway, I don't know about QML, but Qt has QObject::destroyed signal for every QObject:

        This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.

        All the objects's children are destroyed immediately after this signal is emitted.

        I presume that will come before destructor. So maybe you can slot onto that for your purposes.

        1 Reply Last reply Reply Quote 1
        • M
          morte last edited by morte

          I want to do some cleanup actions for external resources in separate thread that is problematic to in destructor itself.

          QObject::destroyed emmited after ~Banner::Banner destructor, i.e. :
          1)QML: banner.destroy()
          2)C++: ~Banner::Banner()
          3)C++: emit QObject::destroyed()
          4)C++: ~QObject::QObject()

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @morte last edited by

            @morte
            If I understand correctly: I don't know what myObject is. But if you want to be notified of Banner's destruction you are supposed to slot onto Banner::destroyed() rather than myObject::destroyed(), if that is what you are doing.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post