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

function return array



  • Hello ,
    who can provide me an example of creating c++ function which return an array .
    then I would like to get this array in another class .
    thank you


  • Lifetime Qt Champion

    Hi,

    QVector<int> generateStuff() {
        QVector<int> vector {1, 2, 3};
        return vector;
    };
    
    class SomeClass
    {
    
    void setVector(const QVector<int> &vector);
    void soSomething();
    };
    
    int main(int argc, char **argv)
    {
        QVector<int> vector = generateStuff();
        SomeClass someClass;
        someClass.setVector(vector);
        someClass.doSomething();
        return 0;
    } 
    

Log in to reply