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

Add a getter "markedForDeletion" to know if deleteLater has been called

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • None
    • Core: Object Model
    • None

    Description

      It would be nice to have the ability to know if an object is marked for deletion to avoid any hoverhead in certain case. It should only be the matter of a boolean to set to true within the deleteLater method.

      For instance, I have a case where a QObject is created via a factory and within that factory I postpone the add of this QObject to a model like so

      QObject* factory(QObject* parent=nullptr)
      {
          QObject* object = new QObject(parent);
          QMetaObject::invokeMethod(this, [this, object](){
              m_objects->append(object);
          }, Qt::QueuedConnection);
          return object;
      }

      the append method can cause some heavy calculation but in some case the deleteLater method of the QObject is called before the end of the event loop so it is not even necessary to append the object. So it would be nice to have the ability to do something like that

      QObject* factory(QObject* parent=nullptr)
      {
          QObject* object = new QObject(parent);
          QMetaObject::invokeMethod(this, [this, object](){
              if(object->isMarkedForDeletion())
                  return;         
              m_objects->append(object);
          }, Qt::QueuedConnection);
          return object;
      }

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              romain.donze Romain Donzé
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes