21 #ifndef QOBJECTUNIQUEPTR_H 22 #define QOBJECTUNIQUEPTR_H 26 #include <qsharedpointer.h> 27 #include <qtypeinfo.h> 42 Q_STATIC_ASSERT_X( !std::is_pointer<T>::value,
"QObjectUniquePtr's template type must not be a pointer type" );
50 struct TypeSelector<const U>
52 typedef const QObject Type;
54 typedef typename TypeSelector<T>::Type QObjectType;
55 QWeakPointer<QObjectType> mPtr;
85 mPtr.swap( other.mPtr );
90 mPtr.assign( static_cast<QObjectType *>( p ) );
99 return static_cast<T *
>( mPtr.data() );
105 inline T *
get()
const 107 return static_cast<T *
>( mPtr.data() );
129 inline operator T *()
const 139 return mPtr.isNull();
147 inline operator bool()
const 149 return !mPtr.isNull();
166 T *p = qobject_cast<T *>( mPtr.data() );
187 return o == p.operator->();
193 return p.operator->() == o;
199 return o == p.operator->();
205 return p.operator->() == o;
211 return p1.operator->() == p2.operator->();
217 return o != p.operator->();
223 return p.operator->() != o;
229 return o != p.operator->();
235 return p.operator->() != o;
241 return p1.operator->() != p2.operator->() ;
248 return QObjectUniquePtr<T>( qobject_cast<T *>( QtSharedPointer::weakPointerFromVariant_internal( variant ).data() ) );
251 #endif // QOBJECTUNIQUEPTR_H T * data() const
Returns the raw pointer to the managed QObject.
bool operator!=(const T *o, const QObjectUniquePtr< T > &p)
bool isNull() const
Checks if the managed pointer is nullptr.
void reset(T *p=nullptr)
Will reset the managed pointer to p.
void swap(QObjectUniquePtr &other)
Swaps the pointer managed by this instance with the pointer managed by other.
~QObjectUniquePtr()
Will delete the contained QObject if it still exists.
QObjectUniquePtr< T > QObjectUniquePtrFromVariant(const QVariant &variant)
QObjectUniquePtr(T *p)
Takes a new QObjectUniquePtr and assigned p to it.
Q_DECLARE_TYPEINFO_BODY(QObjectUniquePtr< T >, Q_MOVABLE_TYPE)
T & operator*() const
Dereferences the managed QObject.
T * release()
Clears the pointer and returns it.
bool operator==(const T *o, const QObjectUniquePtr< T > &p)
QObjectUniquePtr()
Creates a new empty QObjectUniquePtr.
QObjectUniquePtr< T > & operator=(T *p)
void clear()
Clears the pointer.
T * operator->() const
Returns a raw pointer to the managed QObject.
Keeps a pointer to a QObject and deletes it whenever this object is deleted.