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

QList<int> from qml



  • Hi
    I have simple QList<int> which I'm passing to QML with this property:

    Q_PROPERTY(QList<int> days MEMBER m_days NOTIFY daysChanged)
    

    Now I have some function on C++ side to retrieve what has changed on QML side

    Q_INVOKABLE void setSchedData(QString role,QVariant value);
    

    I thought it should work stright away, because Qlist<int> is changed to Array when passing to QML and array is changed to QVariantList when going back to C++
    But this piece of QML code made me some headache:

     var tmp_days=Array.from(WateringSchedModel.days)
    //for(var i=0;i<WateringSchedModel.days.length;i++) {
    //    tmp_days.push(WateringSchedModel.days[i])
    //}
    tmp_days.push(index_role)
    WateringSchedModel.setSchedData("days_role",tmp_days)
    

    it works only with Array.from(exposed_from_cpp) or when I copy elements of days property to tmp_days (commented out), when I use Array.isArray(WateringSchedModel.days) it says false, typeof says object, simply writing:

    var tmp_days=[];
    tmp_days=WateringSchedModel.days
    

    does not work, however I can iterate through tmp_days as if it has been an array, what Am I missing here ?
    Best,
    Marek


Log in to reply