Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it safe to connect a QObject's deleteLater to one of its own signals?

Is it safe to connect a QObject's deleteLater to one of its own signals?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 318 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.
  • S Offline
    S Offline
    Snowdrop
    wrote on last edited by
    #1

    By this I mean if I were to connect an object's deleteLater() to one of its signals, when I emit the signal, is it guaranteed that it will reach all other slots connected to it for the same object? I don't fully grasp the internal workings of the signals/slots mechanism, and I can't confirm this for myself.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by fcarney
      #2

      deleteLater will be called in the order of the signal handlers were attached. However, it won't actually delete well after all the other signals have been handled.

      QObject obj1;
      QObject ob2;
      obj1.connect(&obj1, &QObject::somesig, &obj1, &QObject::deleteLater);
      obj1.connect(&obj1, &QObject::somesig, &obj2, &QObject::otherslot);
      

      This will call deleteLater before otherslot. But the delete won't happen until after these signals have been handled. It won't be until the next iteration of the event loop.

      It is common to use deleteLater with network response objects in addition to handlers on the finished (?) signal. This will cause the object to clean itself up, but the handler will also have an opportunity to "handle" the data.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      3

      • Login

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