[Interest] QSharedpointer members are not accessible: isNull and data

Tamás Nagy tamas.nagy.001 at gmail.com
Fri Oct 23 14:16:08 CEST 2020


Hi,

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)
                {
                    // old code that doesn't compile anymore with Qt 5.12.3
                    //QDomElement dom =
HelperS::Instance()->ValidatorToDomElement(validator.data());
                    // new code that compiles with Qt 5.12.3
                    QDomElement dom =
HelperS::Instance()->ValidatorToDomElement(di.Validator());

                    parameter.appendChild(dom);   // TNagy: .data removed
                }
            }
 }

The problem is that in spite of the QSharedPointer, the members of the
QSharedPointer:
.data() and .isNull() are not accessible at all. I also tried
parentheses but no success.
Sometimes the Validators can be null sometimes not. I have to check if
it is null or not.

What is the problem with the QSharedPointer, why is it not visible in that case?
If I try to use the intellisense on the di.Validator. it lists only
the members of the QValidator.

Tamas


More information about the Interest mailing list