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

C++ properties of type QJSValue are not evaluated correctly

    XMLWordPrintable

Details

    • 9ee6bb0e14d968647350683eafbe80eed7a27058

    Description

      I have a C++ defined property of type QJSValue, and use it in the following QML:

      Item {
          Foo {
              id: literal
              foo: [ { latitude: 5, longitude: 6 } ]
          }
      
          property variant coord1: QtLocation.coordinate(5, 6)
      
          Foo {
              id: prop
              foo: [ coord1 ]
          }
      
          Foo {
              id: func
              foo: [ QtLocation.coordinate(5, 6) ]
          }
      }
      

      Both the literal and prop objects are parsed as expected. For the func object in the foo setter I have verified that the value passed in is correct. I can use QJSValue::toString() to print out the correct value of each item in the array. However, QJSValue::toVariant() returns a QVariant containing a QVariantMap.

      Changing the returned value of QJSValuePrivate::toVariant() from

      return m_engine->variantFromJS(m_value);
      

      to

      return m_engine->toVariant(m_value, -1);
      

      as suggested seems to fix the issue in this case.

      Attachments

        Activity

          People

            chriadam Christopher Adams (closed Nokia identity) (Inactive)
            amccarth Aaron McCarthy (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: