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 convert js array to c++ vector?[solved]

how to convert js array to c++ vector?[solved]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views
  • 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.
  • L Offline
    L Offline
    LeaA
    wrote on 17 May 2015, 09:56 last edited by LeaA
    #1

    hi,

    I want to invoke a c++ function from a js function and I want that the c++ function will get the array that was declared in the js file..
    there is anybody who know how can I do it?

    thanks!

    P 1 Reply Last reply 17 May 2015, 10:16
    0
    • L LeaA
      17 May 2015, 09:56

      hi,

      I want to invoke a c++ function from a js function and I want that the c++ function will get the array that was declared in the js file..
      there is anybody who know how can I do it?

      thanks!

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 17 May 2015, 10:16 last edited by
      #2

      Hi @LeaA,
      Use QVariantList on C++ side. Eg:

      // JavaScript side:
      var cars = ["Saab", "Volvo", "BMW"];
      obj.getJsArray(cars) // getJsArray is a Q_INVOKABLE function on C++ side
      
      //C++ side
      void MyClass::getJsArray(QVariantList list)
      {
          qDebug() << list; //Use toVector() to convert it to vector
      }
      

      157

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeaA
        wrote on 17 May 2015, 12:37 last edited by
        #3

        thank you!

        1 Reply Last reply
        0

        1/3

        17 May 2015, 09:56

        • Login

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