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

QML objectModel



  • Hi,
    i'm trying to create objects list (qml side) with values that i read in file with c++ methode.

    when on_PropValsChanged is emited i have to create object with the properties inside _propVals variant, and i need to keep the objects somewhere i can access it whenever i need

    So i tryed to put my objects in a ObjectModel as described here
    http://doc.qt.io/qt-5/qml-qtqml-models-objectmodel.html
    and show them in ListView

    but as soon i click on my ListView (to scroll) my app crashes

    calling objectMod.get(some index)._name will also result to a crash

    The process was ended forcefully.

    // object creation

     on_PropValsChanged: {
         
            var tmp = _propVals
            var comp = Qt.createComponent("Obj.qml")
            var obj = comp.createObject(cont)
     
            obj._vId=tmp[0]
            obj._name=tmp[1]
            obj._alias = tmp[2]
            obj._slaveId= tmp[3]
            obj._storageType =tmp[4]
            obj._dataType =tmp[5]
            obj._bitSz= tmp[6]
            obj._bitOffset =tmp[7]
            obj._slaveFixAdress = tmp[8]
            obj._type = tmp[9]
            obj._direction = tmp[10]
            obj._index = tmp[11]
            obj._motionType = tmp[12]
            obj._motionDirection = tmp[13]
            obj._motionIndex = tmp[14]
    
            objectMod.append(obj)
       
        }
      ObjectModel {
            id: objectMod
            onChildrenChanged: console.log(children) // the objects are added with the prop values correctly
    
        }
    

    //Obj.qml

    Rectangle {
        property string _vId : ""
        property string _name : ""
        property string _alias : ""
        property string _slaveId : ""
        property string _storageType : ""
        property string _dataType : ""
        property string _bitSz : ""
        property string _bitOffset : ""
        property string _slaveFixAdress : ""
        property string _type : ""
        property string _direction : ""
        property string _index : ""
        property string _motionType : ""
        property string _motionDirection : ""
        property string _motionIndex : ""
    
    
        ColumnLayout{
            anchors.fill: parent
    
            RowLayout{
                Text{
                    text : "variable id :"
                }
                Text{
                    text : _vId
                }
            }
    }
    

    If someone has a better approche please tell me how should i do.
    qt5.11 mingw32






Log in to reply