Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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!


  • Moderators

    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
    }
    


  • thank you!


Log in to reply