Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123598

QML to QJsonObject conversion incompatible with JSON.stringify

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6
    • None
    • All

    Description

      Hello,

      The bug in short is very simple:

      consider a QObject "foo" with a 

      QVector<QString> bar{"a", "b", "c"};

       property  exposed to QML.

      • console.log(JSON.stringify(foo.bar))

          gives 

        [ 'a', 'b', 'c' ]

         as expected.

       

      • passing the object to a C++ slot that takes in argument a QJsonObject from QML, e.g.: 
        backend.toJson(foo.bar)

         gives on the other hand the following JSON structure:

         { "0": "a", "1": "b", "2": "c" }
        

      e.g. the array gets transformed into a map, with each index being a key.

      This is a somewhat surprising and confusing behaviour. It happens of course recursively, e.g. I'm passing a root object that contains at some point a child, child, child member of this type which gets incorrectly converted.

       

      Attached: full repro

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jcelerier Jean-Michaël Celerier
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes