Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to pass QVariantList from a c++ function to QtScript function ?

How to pass QVariantList from a c++ function to QtScript function ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 743 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtVik
    wrote on last edited by QtVik
    #1

    Hi,

    How to to pass QVariantList from a c++ function to QtScript function ?

    example:
    qt script:
    function evaluate( var valueList )
    {
    var output = valueList[0] + valueList[1];
    return output;
    }

    How to pass value to the above qt script from the c++ code?
    I have QVariantList variable that needs to be passed as argument to the above function and get the output value as QList<QList<qreal> >
    The valueList above contains qreal values. QVariantList contains QList<QList<qreal> >

    raven-worxR Gojir4G 2 Replies Last reply
    0
    • Q QtVik

      Hi,

      How to to pass QVariantList from a c++ function to QtScript function ?

      example:
      qt script:
      function evaluate( var valueList )
      {
      var output = valueList[0] + valueList[1];
      return output;
      }

      How to pass value to the above qt script from the c++ code?
      I have QVariantList variable that needs to be passed as argument to the above function and get the output value as QList<QList<qreal> >
      The valueList above contains qreal values. QVariantList contains QList<QList<qreal> >

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @QtVik

      First of all the QtScript module is deprecated.
      If you do not depend on QtScript you should rather use QJSEngine (from the QtQml module) - or even QQmlEngine if you like.

      The valueList above contains qreal values. QVariantList contains QList<QList<qreal> >

      A nested QList wont make it to QtScript/QML.
      Only nested QVariantLists is possible in this case.

      For a better understanding. If you need to pass something from C++ to QtScript/QML everything should be a packed into a QVariant.

      You might also want to take a look at the implicit type conversions.
      I dont know if this is handled by QJSEngine or only by QQmlEngine though. But anyway you can use QQmlEngine as i said.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • Q QtVik

        Hi,

        How to to pass QVariantList from a c++ function to QtScript function ?

        example:
        qt script:
        function evaluate( var valueList )
        {
        var output = valueList[0] + valueList[1];
        return output;
        }

        How to pass value to the above qt script from the c++ code?
        I have QVariantList variable that needs to be passed as argument to the above function and get the output value as QList<QList<qreal> >
        The valueList above contains qreal values. QVariantList contains QList<QList<qreal> >

        Gojir4G Offline
        Gojir4G Offline
        Gojir4
        wrote on last edited by
        #3

        @QtVik Hi,

        Use QScriptEngine::toScriptValue<T>() :

        QVariantList listIn;
        listIn << 123 << "hello";
        QScriptValue array = scriptEngine->toScriptValue(listIn);
        
        Q 1 Reply Last reply
        2
        • Gojir4G Gojir4

          @QtVik Hi,

          Use QScriptEngine::toScriptValue<T>() :

          QVariantList listIn;
          listIn << 123 << "hello";
          QScriptValue array = scriptEngine->toScriptValue(listIn);
          
          Q Offline
          Q Offline
          QtVik
          wrote on last edited by
          #4

          @Gojir4 @raven-worx

          Thank you so much for the inputs.

          @Gojir4 : The hint provided by you helped me. Thank you so much.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved