[Development] Behaviour change in QML in Qt 5.8 regarding null

Allan Sandfeld Jensen kde at carewolf.com
Wed Sep 28 14:53:01 CEST 2016

On Wednesday 28 September 2016, Olivier Goffart wrote:
> int main() {
>     QVariant v1 =  QVariant::fromValue<void*>(nullptr);
>     QVariant v2 =  QVariant::fromValue(nullptr);
>     qDebug() << v1.isNull() << v2.isNull() << (v1 == v2) << (v2 == v1);
>     qDebug() << v2.canConvert<void*>()  << v2.canConvert<QObject*>();
> }
> // output:
> // "false false false false"
> // "false false"
> IMHO this is wrong!
> First of all, I'm not even convinced it makes sens to have std::nullptr_t
> as a builtin type.
> I think any pointer type with nullptr in it should be isNull()
> All we need a specialisation of QVariantIsNull::CallFilteredIsNull for T*
> and for std::nullptr_t.
> That would be a change of behaviour for T* tough. But not for nullptr_t
> since it's new.
> Also I think nullptr_t should be convertible to any pointer type.
> (nullptr_t is converting top any pointer type in the c++ world)
> And that should solve the equality problem.

I would agree, but after looking into the code, I think we have a major 
problem. QVariant::isNull is used for two things, one it maps to isNull on any 
complex classes, but during conversion anything null can't be converted and 
null afterwards indicate a failed conversion. Convert should probably be using 
QVariant::Invalid, but it currently doesn't.

In general we have not separated invalid and null well in the past, and trying 
to fix that will cause issues.


More information about the Development mailing list