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

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

      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

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes