[Interest] QSharedpointer members are not accessible: isNull and data
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Fri Oct 23 14:30:22 CEST 2020
Hi,
On 23/10/2020 14:16, Tamás Nagy wrote:
> class A
> {
> public:
> ....
> private:
> QSharedPointer<QValidator> m_Validator;
> }
>
> My custom program:
>
> if(di.Validator()->isNull())
> {
> // unfortunately the di.Validator() is null
> // some A-s in the Map can have nullptr as Validator.
>
> if(auto validator = di.Validator()) // di is an instance of A
> {
> if(validator != nullptr)
> {
I'm having quite a hard time understanding this code.
In the first if, you dereference the result of di.Validator(). This
implies it's not null.
Then immediately after you fetch di.Validator() again, assign it to
"validator", and in the second if you ask if it's not null -- but... you
already know?.
Then in the third if you ask *again*. What's going on here?
Can you put together a minimal but complete, correct, and compileable
testcase?
Thanks,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20201023/6eba125d/attachment.bin>
More information about the Interest
mailing list