[Development] QVariantMap <-> QML

Ben Lau xbenlau at gmail.com
Sun Jun 14 19:45:39 CEST 2015


On 15 June 2015 at 01:43, Gerhard Scheikl <g.scheikl at avibit.com> wrote:

> Hi
>
> I recently discovered some unexpected behavior when exchanging a
> QVariantMap
> with QML code:
>
> Here's what I'm doing on the C++ side:
> my_map = json_document.toVariant();
> engine.rootContext()->setContextProperty("myMap", my_map);
>
> Then on the QML side:
> myMap.asdf.name = "asdf"
>
> This change is not reflected in the original map.
> Obviously, accessing asdf.name returns a copy.
>
> Is this the intended behavior?
> If so, how can I ensure that the data in C++ and on the QML side is always
> the
> same?
> (use QJSValue? use a QObject hierarchy with dynamic properties?)
>
> Thanks!
>
>

var tmp = myMap.asdf;
tmp.name = "asdf"
myMap.asdf = tmp;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150615/fa7e9584/attachment.html>


More information about the Development mailing list