18#include <private/qqmldata_p.h>
19#include <private/qqmlglobal_p.h>
26 using ObjectDestroyedFn =
void(*)(QQmlGuardImpl *);
28 inline QQmlGuardImpl();
29 inline QQmlGuardImpl(QObject *);
30 inline QQmlGuardImpl(
const QQmlGuardImpl &);
32 inline ~QQmlGuardImpl();
36 QQmlGuardImpl *next =
nullptr;
37 QQmlGuardImpl **prev =
nullptr;
38 ObjectDestroyedFn objectDestroyed =
nullptr;
40 inline void addGuard();
41 inline void remGuard();
43 inline void setObject(QObject *g);
44 bool isNull()
const noexcept {
return !o; }
51 friend class QQmlData;
61 T *
object()
const noexcept {
return static_cast<T *>(o); }
62 void setObject(T *g) { QQmlGuardImpl::setObject(g); }
64 using QQmlGuardImpl::isNull;
73
74
75
76
77void Q_QML_EXPORT hasJsOwnershipIndicator(QQmlGuardImpl *);
80class QQmlStrongJSQObjectReference
final :
protected QQmlGuardImpl
83 T *
object()
const noexcept {
return static_cast<T *>(o); }
85 using QQmlGuardImpl::isNull;
97 if (hasJsOwnership() && old && old->parent() == parent)
98 QQml_setParent_noEvent(old,
nullptr);
100 QQmlGuardImpl::setObject(obj);
102 if (obj && !obj->parent() && !QQmlData::keepAliveDuringGarbageCollection(obj)) {
103 setJsOwnership(
true);
104 QQml_setParent_noEvent(obj, parent);
106 setJsOwnership(
false);
111 bool hasJsOwnership() {
112 return objectDestroyed == hasJsOwnershipIndicator;
115 void setJsOwnership(
bool itHasOwnership) {
116 objectDestroyed = itHasOwnership ? hasJsOwnershipIndicator :
nullptr;
122Q_DECLARE_METATYPE(QQmlGuard<QObject>)
126QQmlGuardImpl::QQmlGuardImpl()
130QQmlGuardImpl::QQmlGuardImpl(QObject *g)
137
138
139
140
141
142
143QQmlGuardImpl::QQmlGuardImpl(
const QQmlGuardImpl &g)
144: o(g.o), objectDestroyed(g.objectDestroyed)
149QQmlGuardImpl::~QQmlGuardImpl()
151 if (prev) remGuard();
155void QQmlGuardImpl::addGuard()
159 if (QObjectPrivate::get(o)->wasDeleted)
162 QQmlData *data = QQmlData::get(o,
true);
164 if (next) next->prev = &next;
166 prev = &data->guards;
169void QQmlGuardImpl::remGuard()
173 if (next) next->prev = prev;
180QQmlGuard<T>::QQmlGuard()
185QQmlGuard<T>::QQmlGuard(ObjectDestroyedFn objDestroyed, T *obj)
188 objectDestroyed = objDestroyed;
192QQmlGuard<T>::QQmlGuard(T *g)
198QQmlGuard<T>::QQmlGuard(
const QQmlGuard<T> &g)
204QQmlGuard<T> &QQmlGuard<T>::operator=(
const QQmlGuard<T> &g)
206 objectDestroyed = g.objectDestroyed;
207 setObject(g.object());
212QQmlGuard<T> &QQmlGuard<T>::operator=(T *g)
215
216
217
222void QQmlGuardImpl::setObject(QObject *g)
225 if (prev) remGuard();
QQmlGuard< T > & operator=(T *)
operator T*() const noexcept
T * operator->() const noexcept
T * object() const noexcept
QQmlGuard< T > & operator=(const QQmlGuard< T > &o)
T * data() const noexcept
T * object() const noexcept
operator T*() const noexcept
T * operator->() const noexcept
void setObject(T *obj, QObject *parent)
T * data() const noexcept
QDebug Q_QML_EXPORT operator<<(QDebug debug, const QQmlError &error)