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

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

XMLWordPrintable

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

      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;
      }

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes