Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get notified that object gonna be destroyed
QtWS25 Last Chance

Get notified that object gonna be destroyed

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.2k Views
  • 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 Offline
    M Offline
    morte
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • M morte

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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
      1
      • M Offline
        M Offline
        morte
        wrote on last edited by morte
        #3

        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()

        JonBJ 1 Reply Last reply
        0
        • M 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()

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved