deferred: don't delete self, to allow smart pointers to manage#48174
Merged
deferred: don't delete self, to allow smart pointers to manage#48174
Conversation
jkarneges
commented
Mar 21, 2025
|
|
||
| class RefreshWorker : public Deferred | ||
| { | ||
| Q_OBJECT |
Member
Author
There was a problem hiding this comment.
Technically this should be here since Deferred inherits from QObject, but probably not for much longer.
deg4uss3r
approved these changes
Mar 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Deferredclass provides a generic interface for an async operation, signaling aQVariantresult. Currently it deletes itself upon completion (literally withdelete this), intended to enable a fire-and-forget developer experience when used along withQObjectparenting. The idea is whether it completes or its parent goes away, it is automatically cleaned up, without the caller needing to explicitly track it. However, we are trying to avoidQObjectparenting, preferring to use smart pointers instead, and self-destruction is incompatible with smart pointers.In order to allow
Deferredinstances to be managed with smart pointers, this PR removes the self destruction and updates all the placesDeferredis used to ensure instances are destroyed on completion or when the parent/owner goes away. In some places we were already using smart pointers to manage some instances, which was almost certainly wrong (possibly leading to double-deletions) and this PR fixes those cases too.The resulting developer experience is not as nice but at least this fixes some wrongness and helps get us off
QObject.