19#include <private/qqmldata_p.h>
20#include <private/qqmlglobal_p.h>
27 using ObjectDestroyedFn =
void(*)(QQmlGuardImpl *);
29 inline QQmlGuardImpl();
30 inline QQmlGuardImpl(QObject *);
31 inline QQmlGuardImpl(
const QQmlGuardImpl &);
33 inline ~QQmlGuardImpl();
37 QQmlGuardImpl *next =
nullptr;
38 QQmlGuardImpl **prev =
nullptr;
39 ObjectDestroyedFn objectDestroyed =
nullptr;
41 inline void addGuard();
42 inline void remGuard();
44 inline void setObject(QObject *g);
45 bool isNull()
const noexcept {
return !o; }
52 friend class QQmlData;
62 T *
object()
const noexcept {
return static_cast<T *>(o); }
63 void setObject(T *g) { QQmlGuardImpl::setObject(g); }
65 using QQmlGuardImpl::isNull;
74
75
76
77
78void Q_QML_EXPORT hasJsOwnershipIndicator(QQmlGuardImpl *);
81class QQmlStrongJSQObjectReference
final :
protected QQmlGuardImpl
84 T *
object()
const noexcept {
return static_cast<T *>(o); }
86 using QQmlGuardImpl::isNull;
98 if (hasJsOwnership() && old && old->parent() == parent)
99 QQml_setParent_noEvent(old,
nullptr);
101 QQmlGuardImpl::setObject(obj);
103 if (obj && !obj->parent() && !QQmlData::keepAliveDuringGarbageCollection(obj)) {
104 setJsOwnership(
true);
105 QQml_setParent_noEvent(obj, parent);
107 setJsOwnership(
false);
112 bool hasJsOwnership() {
113 return objectDestroyed == hasJsOwnershipIndicator;
116 void setJsOwnership(
bool itHasOwnership) {
117 objectDestroyed = itHasOwnership ? hasJsOwnershipIndicator :
nullptr;
123Q_DECLARE_METATYPE(QQmlGuard<QObject>)
127QQmlGuardImpl::QQmlGuardImpl()
131QQmlGuardImpl::QQmlGuardImpl(QObject *g)
138
139
140
141
142
143
144QQmlGuardImpl::QQmlGuardImpl(
const QQmlGuardImpl &g)
145: o(g.o), objectDestroyed(g.objectDestroyed)
150QQmlGuardImpl::~QQmlGuardImpl()
152 if (prev) remGuard();
156void QQmlGuardImpl::addGuard()
160 if (QObjectPrivate::get(o)->wasDeleted)
163 QQmlData *data = QQmlData::get(o,
true);
165 if (next) next->prev = &next;
167 prev = &data->guards;
170void QQmlGuardImpl::remGuard()
174 if (next) next->prev = prev;
181QQmlGuard<T>::QQmlGuard()
186QQmlGuard<T>::QQmlGuard(ObjectDestroyedFn objDestroyed, T *obj)
189 objectDestroyed = objDestroyed;
193QQmlGuard<T>::QQmlGuard(T *g)
199QQmlGuard<T>::QQmlGuard(
const QQmlGuard<T> &g)
205QQmlGuard<T> &QQmlGuard<T>::operator=(
const QQmlGuard<T> &g)
207 objectDestroyed = g.objectDestroyed;
208 setObject(g.object());
213QQmlGuard<T> &QQmlGuard<T>::operator=(T *g)
216
217
218
223void QQmlGuardImpl::setObject(QObject *g)
226 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)