diff --git a/src/core/qobjectuniqueptr.h b/src/core/qobjectuniqueptr.h index 5a578d506f9..31ad1308d81 100644 --- a/src/core/qobjectuniqueptr.h +++ b/src/core/qobjectuniqueptr.h @@ -91,6 +91,14 @@ class QObjectUniquePtr return static_cast( mPtr.data() ); } + /** + * Returns the raw pointer to the managed QObject. + */ + inline T *get() const + { + return static_cast( 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(); diff --git a/tests/src/core/testqobjectuniqueptr.cpp b/tests/src/core/testqobjectuniqueptr.cpp index 1c5462a0d81..6a2bf1902d1 100644 --- a/tests/src/core/testqobjectuniqueptr.cpp +++ b/tests/src/core/testqobjectuniqueptr.cpp @@ -43,9 +43,13 @@ void TestQObjectUniquePtr::testParentDeletedFirst() QObjectUniquePtr 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()