Details
-
Suggestion
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
None
-
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
- relates to
-
QTBUG-120124 Improvements to deferred deletions / deleteLater()
- Open