Add get() and operator bool() to QObjectUniquePointer

This commit is contained in:
Matthias Kuhn 2019-06-10 19:19:23 +02:00
parent 8197e00c7b
commit 590f654f3f
2 changed files with 17 additions and 0 deletions

View File

@ -91,6 +91,14 @@ class QObjectUniquePtr
return static_cast<T *>( mPtr.data() );
}
/**
* Returns the raw pointer to the managed QObject.
*/
inline T *get() const
{
return static_cast<T *>( mPtr.data() );
}
/**
* Returns a raw pointer to the managed QObject.
*/
@ -123,6 +131,11 @@ class QObjectUniquePtr
return mPtr.isNull();
}
inline bool operator bool() const
{
return !mPtr.isNull();
}
inline void clear()
{
mPtr.clear();

View File

@ -43,9 +43,13 @@ void TestQObjectUniquePtr::testParentDeletedFirst()
QObjectUniquePtr<QObject> obj( child );
QVERIFY( !obj.isNull() );
QVERIFY( obj );
QCOMPARE( child, obj.get() );
QCOMPARE( child, obj.data() );
delete parent;
QVERIFY( obj.isNull() );
QVERIFY( !obj );
}
void TestQObjectUniquePtr::testParentDeletedAfter()