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

Olivier Goffart olivier at woboq.com
Wed Sep 28 12:41:16 CEST 2016


On Mittwoch, 28. September 2016 10:39:42 CEST Allan Sandfeld Jensen wrote:
> On Wednesday 28 September 2016, Thiago Macieira wrote:
> > On quarta-feira, 28 de setembro de 2016 01:22:33 PDT Allan Sandfeld Jensen
> > 
> > wrote:
> > > > QVariant::fromValue(nullptr).isNull() == false
> > > > QVariant(QMetaType::Nullptr).isNull() == true
> > > 
> > > And QVariant(nullptr) doesn't compile.
> > > 
> > > We should probably fix the fromValue constructor.
> > 
> > I don't think so. This is also false:
> > 	QVariant::fromValue<void *>(nullptr).isNull()
> 
> Is QVariant(QMetaType::VoidStar).isNull()  true?
> 
> Since nullptr is new, I would prefer if we could avoid having it too quirky
> to begin with.
> 
> `allan

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.

-- 
Olivier

Woboq - Qt services and support - https://woboq.com - https://code.woboq.org



More information about the Development mailing list