[Development] Qml/JS QVariantMap conversion problem

Simon Hausmann simon.hausmann at digia.com
Thu Sep 25 09:48:13 CEST 2014


On Thursday 25. September 2014 09.44.51 Nils Jeisecke wrote:
> Hi Simon,
> 
> thank you very much for the explanation. No need for bug hunting then.
> 
> On Thu, Sep 25, 2014 at 7:55 AM, Simon Hausmann
> 
> <simon.hausmann at digia.com> wrote:
> > We've changed this in Qt 5.4 slightly: When
> > converting a JavaScript object back to a QVariant, we won't try to
> > "destroy" it but instead we'll give you a QVariant that holds a (strong)
> > reference to the JavaScript object, it'll be a QJSValue in a QVariant.
> > Note how somebody could call setMap with the return value of buildMap()
> > but also with a JS object literal: setMap( { x: ["a", "b" ] })
> > 
> >     QVariant(QVariantMap, QMap(("x", QVariant(QStringList, ("a", "b")) ) )
> >     )
> > 
> > You can do the conversion like this:
> >     QVariant map = ...
> >     if (map.userType() == qMetaTypeId<QJSValue>())
> >     
> >         map = qvariant_cast<QJSValue>(map).toVariant();
> 
> I think this should be added to the documentation. Maybe here:
> http://doc-snapshot.qt-project.org/qt5-5.4/qtqml-cppintegration-data.html.
> I'd give it a try if this is the right place.

Yes, that looks like the right place.
 

Simon



More information about the Development mailing list