Skip to content

Commit

Permalink
Add get() and operator bool() to QObjectUniquePointer
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 10, 2019
1 parent 8197e00 commit 590f654
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/qobjectuniqueptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -123,6 +131,11 @@ class QObjectUniquePtr
return mPtr.isNull();
}

inline bool operator bool() const
{
return !mPtr.isNull();
}

inline void clear()
{
mPtr.clear();
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqobjectuniqueptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 590f654

Please sign in to comment.