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

QByteArray can no longer be passed to JSON.parse()

XMLWordPrintable

      #include <QtQml>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          QQmlEngine engine;
      
          QByteArray data = "{ \"foo\":\"bar\" }";
          engine.rootContext()->setContextProperty("byteArrayData", data);
          engine.rootContext()->setContextProperty("stringData", QString::fromUtf8(data));
      
          QQmlComponent component(&engine);
          component.setData("import QtQml 2.0; QtObject { Component.onCompleted: JSON.parse(stringData) }", QUrl("string"));
          component.create(); // ok
      
          component.setData("import QtQml 2.0; QtObject { Component.onCompleted: JSON.parse(byteArrayData) }", QUrl("bytearray"));
          component.create(); // bytearray:1: JSON.parse: Parse error
      }
      

      Presumably https://codereview.qt-project.org/#/c/144761/

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

            shausman Simon Hausmann
            jpnurmi J-P Nurmi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes