Retainable: QtObject [uncreatable]

import Quickshell

Attached object for types that can have delayed destruction. More

Properties

Functions

Signals

Detailed Description

Retainable works as an attached property that allows objects to be kept around (retained) after they would normally be destroyed, which is especially useful for things like exit transitions.

An object that is retainable will have Retainable as an attached property. All retainable objects will say that they are retainable on their respective typeinfo pages.

ℹ️
Working directly with Retainable is often overly complicated and error prone. For this reason RetainableLock should usually be used instead.

Property Details

[readonly]

retained: bool

If the object is currently in a retained state.

Function Details

void forceUnlock()

Forcibly remove all locks, destroying the object.

unlock() should usually be preferred.

void lock()

Hold a lock on the object so it cannot be destroyed.

A counter is used to ensure you can lock the object from multiple places and it will not be unlocked until the same number of unlocks as locks have occurred.

⚠️

It is easy to forget to unlock a locked object. Doing so will create what is effectively a memory leak.

Using RetainableLock is recommended as it will help avoid this scenario and make misuse more obvious.

void unlock()

Remove a lock on the object. See lock() for more information.

Signal Details

aboutToDestroy()

This signal is sent immediately before the object is destroyed. At this point destruction cannot be interrupted.

dropped()

This signal is sent when the object would normally be destroyed.

If all signal handlers return and no locks are in place, the object will be destroyed. If at least one lock is present the object will be retained until all are removed.