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

QTScript default conversion from Qt Script to C++ fails with objects as properties of objects

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 4.7.0
    • 4.3.0
    • Qt Script
    • None
    • openSUSE 11.2, x86_64

    Description

      calling a C++ function from a script with an object containing object members results in the object member being converted to a QString instead of a QVariantMap as documented and as the embedding object has been converted to.

      code snippet (excerpt):

      — script —
      var obj = { foo1: "bar", foo2:

      { a:1 }

      };
      globalObject.func(obj);

      — c++ —
      void MyObject::func(QVariantMap obj) {
      qDebug() << obj.value("foo1").toString() << obj.value("foo2").value<QVariantMap>();
      }

      possible solution: convert the QScriptValue recursively like this:
      QVariantMap convertScriptObject(const QScriptValue& object) {
      QVariantMap result;

      QScriptValueIterator it(object);
      if (object.isObject()) {
      while (it.hasNext()) {
      it.next();
      if (it.value().isObject())

      { result.insert(it.name(), convertScriptObject(it.value())); }

      else

      { result.insert(it.name(), it.value().toVariant()); }

      }
      }

      return result;
      }

      OR

      fixe QScriptValue.toVariant() for this case

      Attachments

        Issue Links

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

          Activity

            People

              kenthans Kent Hansen (Inactive)
              nico.laus Nico Kruber
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes