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

Simon Hausmann Simon.Hausmann at qt.io
Wed Sep 28 10:54:10 CEST 2016


Ok, let me clarify: When the JavaScript engine wants to map a JS null value to a QVariant, it used to use

    QVariant(QMetaType::VoidStar, (void *)0);

and now uses


If a string is to be converted to a QVariant, it will naturally use QVariant(thatString). I think if that

string happens to be a null QString, then QVariant isNull() will return true, right?

If that is unsufficient for the pim code here (or generally any other code), then my recommendation

would be to change the signature to take a QJSValue instead of a QVariant. The engine supports that

transparently and the QJSValue API allows distinguishing between a JavaScript null and a string, etc.

So that is another option.


From: Development <development-bounces+simon.hausmann=qt.io at qt-project.org> on behalf of Thiago Macieira <thiago.macieira at intel.com>
Sent: Tuesday, September 27, 2016 11:59:50 PM
To: development at qt-project.org
Subject: Re: [Development] Behaviour change in QML in Qt 5.8 regarding null

On terça-feira, 27 de setembro de 2016 18:22:34 PDT Simon Hausmann wrote:
> I'm fairly sure we used QVariant(QMetaType::VoidStar);

Can you guarantee that the only time the QML engine generates null QVariants
is for null JS Values? That is, no null QStrings, null QVariantLists, null
QVariantMaps/Hahes, null doubles, etc.?

If that's the case, I'd recommend a doc update and unit tests. Chris can fix
his code for isNull().

        QVariant::fromValue(nullptr).isNull() == false
        QVariant(QMetaType::Nullptr).isNull() == true

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

Development mailing list
Development at qt-project.org
Development Info Page - Qt<http://lists.qt-project.org/mailman/listinfo/development>
To see the collection of prior postings to the list, visit the Development Archives. Using Development: To post a message to all the list members ...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160928/b4d029fd/attachment.html>

More information about the Development mailing list