QPointer check is NULL?

2.1k Views Asked by At

When I delete the object the QPointer is pointing to, I check the value of the QPointer, and it is not NULL, but when I check its isNull function, it returns true.

And more strangely, when I do (!m_qpointer) it also returns true. So how is this possible?

1

There are 1 best solutions below

0
On BEST ANSWER

(!m_qpointer) returns true when you delete the object it is pointing to, because of this operator defined in qpointer.h:

inline operator T*() const
    { return static_cast<T*>(const_cast<QObject*>(o)); }

It returns the pointer it is guarding. If it has been deleted, then it will be null.

isNull() returns true if the pointer it is guarding is null:

inline bool isNull() const
    { return !o; }

Now I'm not sure what do you mean by I check the value of the QPointer, and it is not NULL. Why should it be null? The QPointer object should still be a valid object even after deleting the pointer it is guarding.